fix(router): state data missing in routerLink (#36462)

fixes #33173 - router state data is missing on routerLink when used
with non-anchor elements.

PR Close #36462
This commit is contained in:
Andrew Scott 2020-04-06 13:39:33 -07:00 committed by Kara Erickson
parent af4269471d
commit 0e7a89a391
2 changed files with 234 additions and 179 deletions

View File

@ -7,7 +7,7 @@
*/
import {LocationStrategy} from '@angular/common';
import {Attribute, Directive, ElementRef, HostBinding, HostListener, Input, OnChanges, OnDestroy, Renderer2, isDevMode} from '@angular/core';
import {Attribute, Directive, ElementRef, HostBinding, HostListener, Input, isDevMode, OnChanges, OnDestroy, Renderer2} from '@angular/core';
import {Subscription} from 'rxjs';
import {QueryParamsHandling} from '../config';
@ -163,6 +163,7 @@ export class RouterLink {
const extras = {
skipLocationChange: attrBoolValue(this.skipLocationChange),
replaceUrl: attrBoolValue(this.replaceUrl),
state: this.state,
};
this.router.navigateByUrl(this.urlTree, extras);
return true;
@ -244,8 +245,12 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
this.preserve = value;
}
ngOnChanges(changes: {}): any { this.updateTargetUrlAndHref(); }
ngOnDestroy(): any { this.subscription.unsubscribe(); }
ngOnChanges(changes: {}): any {
this.updateTargetUrlAndHref();
}
ngOnDestroy(): any {
this.subscription.unsubscribe();
}
@HostListener('click', ['$event.button', '$event.ctrlKey', '$event.metaKey', '$event.shiftKey'])
onClick(button: number, ctrlKey: boolean, metaKey: boolean, shiftKey: boolean): boolean {

View File

@ -9,11 +9,11 @@
import {CommonModule, Location} from '@angular/common';
import {SpyLocation} from '@angular/common/testing';
import {ChangeDetectionStrategy, Component, Injectable, NgModule, NgModuleFactoryLoader, NgModuleRef, NgZone, OnDestroy, ɵConsole as Console, ɵNoopNgZone as NoopNgZone} from '@angular/core';
import {ComponentFixture, TestBed, fakeAsync, inject, tick} from '@angular/core/testing';
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser/src/dom/debug/by';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DefaultUrlSerializer, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, Navigation, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, PRIMARY_OUTLET, ParamMap, Params, PreloadAllModules, PreloadingStrategy, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouteReuseStrategy, Router, RouterEvent, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlSerializer, UrlTree} from '@angular/router';
import {Observable, Observer, Subscription, of } from 'rxjs';
import {ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DefaultUrlSerializer, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, Navigation, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ParamMap, Params, PreloadAllModules, PreloadingStrategy, PRIMARY_OUTLET, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, Router, RouteReuseStrategy, RouterEvent, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlSerializer, UrlTree} from '@angular/router';
import {Observable, Observer, of, Subscription} from 'rxjs';
import {filter, first, map, tap} from 'rxjs/operators';
import {forEach} from '../src/utils/collection';
@ -255,7 +255,9 @@ describe('Integration', () => {
let warnings: string[] = [];
class MockConsole {
warn(message: string) { warnings.push(message); }
warn(message: string) {
warnings.push(message);
}
}
beforeEach(() => {
@ -266,7 +268,9 @@ describe('Integration', () => {
describe('with NgZone enabled', () => {
it('should warn when triggered outside Angular zone',
fakeAsync(inject([Router, NgZone], (router: Router, ngZone: NgZone) => {
ngZone.runOutsideAngular(() => { router.navigateByUrl('/simple'); });
ngZone.runOutsideAngular(() => {
router.navigateByUrl('/simple');
});
expect(warnings.length).toBe(1);
expect(warnings[0])
@ -276,19 +280,24 @@ describe('Integration', () => {
it('should not warn when triggered inside Angular zone',
fakeAsync(inject([Router, NgZone], (router: Router, ngZone: NgZone) => {
ngZone.run(() => { router.navigateByUrl('/simple'); });
ngZone.run(() => {
router.navigateByUrl('/simple');
});
expect(warnings.length).toBe(0);
})));
});
describe('with NgZone disabled', () => {
beforeEach(() => { TestBed.overrideProvider(NgZone, {useValue: new NoopNgZone()}); });
beforeEach(() => {
TestBed.overrideProvider(NgZone, {useValue: new NoopNgZone()});
});
it('should not warn when triggered outside Angular zone',
fakeAsync(inject([Router, NgZone], (router: Router, ngZone: NgZone) => {
ngZone.runOutsideAngular(() => { router.navigateByUrl('/simple'); });
ngZone.runOutsideAngular(() => {
router.navigateByUrl('/simple');
});
expect(warnings.length).toBe(0);
})));
@ -331,18 +340,24 @@ describe('Integration', () => {
@Component({template: '<router-outlet></router-outlet>'})
class Parent {
constructor(route: ActivatedRoute) {
route.params.subscribe((s: any) => { log.push(s); });
route.params.subscribe((s: any) => {
log.push(s);
});
}
}
@Component({template: 'child1'})
class Child1 {
ngOnDestroy() { log.push('child1 destroy'); }
ngOnDestroy() {
log.push('child1 destroy');
}
}
@Component({template: 'child2'})
class Child2 {
constructor() { log.push('child2 constructor'); }
constructor() {
log.push('child2 constructor');
}
}
@NgModule({
@ -382,7 +397,6 @@ describe('Integration', () => {
'child2 constructor',
]);
})));
});
it('should not wait for prior navigations to start a new navigation',
@ -412,7 +426,6 @@ describe('Integration', () => {
'trueRightAway', 'trueIn2Seconds-start', 'trueRightAway', 'trueIn2Seconds-start',
'trueIn2Seconds-end', 'trueIn2Seconds-end'
]);
})));
});
@ -464,11 +477,9 @@ describe('Integration', () => {
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
const fixture = createRoot(router, RootCmp);
router.resetConfig([{
path: 'team/:id',
component: TeamCmp,
children: [{path: 'simple', component: SimpleCmp}]
}]);
router.resetConfig([
{path: 'team/:id', component: TeamCmp, children: [{path: 'simple', component: SimpleCmp}]}
]);
router.navigateByUrl('/team/33/simple');
advance(fixture);
@ -535,7 +546,9 @@ describe('Integration', () => {
@Component({template: `record`})
class RecordLocationCmp {
private storedPath: string;
constructor(loc: Location) { this.storedPath = loc.path(); }
constructor(loc: Location) {
this.storedPath = loc.path();
}
}
@NgModule({declarations: [RecordLocationCmp], entryComponents: [RecordLocationCmp]})
@ -632,11 +645,12 @@ describe('Integration', () => {
providers: [{
provide: 'authGuardFail',
useValue: (a: any, b: any) => {
return new Promise(res => { setTimeout(() => res(serializer.parse('/login')), 1); });
return new Promise(res => {
setTimeout(() => res(serializer.parse('/login')), 1);
});
}
}]
});
});
@ -758,7 +772,6 @@ describe('Integration', () => {
it('should should set `state` with urlUpdateStrategy="eagar"',
fakeAsync(inject([Router, Location], (router: Router, location: SpyLocation) => {
router.urlUpdateStrategy = 'eager';
router.resetConfig([
{path: '', component: SimpleCmp},
@ -1295,7 +1308,6 @@ describe('Integration', () => {
// we do not trigger another navigation to /simple
expect(events).toEqual(['/simple', '/throwing']);
}));
});
it('should dispatch NavigationCancel after the url has been reset back', fakeAsync(() => {
@ -1360,8 +1372,9 @@ describe('Integration', () => {
it('should support custom malformed uri error handler',
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
const customMalformedUriErrorHandler =
(e: URIError, urlSerializer: UrlSerializer, url: string):
UrlTree => { return urlSerializer.parse('/?error=The-URL-you-went-to-is-invalid'); };
(e: URIError, urlSerializer: UrlSerializer, url: string): UrlTree => {
return urlSerializer.parse('/?error=The-URL-you-went-to-is-invalid');
};
router.malformedUriErrorHandler = customMalformedUriErrorHandler;
router.resetConfig([{path: 'simple', component: SimpleCmp}]);
@ -1482,9 +1495,13 @@ describe('Integration', () => {
activations: any[] = [];
deactivations: any[] = [];
recordActivate(component: any): void { this.activations.push(component); }
recordActivate(component: any): void {
this.activations.push(component);
}
recordDeactivate(component: any): void { this.deactivations.push(component); }
recordDeactivate(component: any): void {
this.deactivations.push(component);
}
}
TestBed.configureTestingModule({declarations: [Container]});
@ -1517,7 +1534,6 @@ describe('Integration', () => {
it('should update url and router state before activating components',
fakeAsync(inject([Router], (router: Router) => {
const fixture = createRoot(router, RootCmp);
router.resetConfig([{path: 'cmp', component: ComponentRecordingRoutePathAndUrl}]);
@ -1535,7 +1551,9 @@ describe('Integration', () => {
describe('data', () => {
class ResolveSix implements Resolve<number> {
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): number { return 6; }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): number {
return 6;
}
}
beforeEach(() => {
@ -1764,9 +1782,8 @@ describe('Integration', () => {
router.resetConfig([{
path: 'team/:id',
component: TeamCmp,
children: [
{path: 'link', component: StringLinkCmp}, {path: 'simple', component: SimpleCmp}
]
children:
[{path: 'link', component: StringLinkCmp}, {path: 'simple', component: SimpleCmp}]
}]);
router.navigateByUrl('/team/22/link');
@ -1825,7 +1842,6 @@ describe('Integration', () => {
}));
it('should update hrefs when query params or fragment change', fakeAsync(() => {
@Component({
selector: 'someRoot',
template:
@ -1855,7 +1871,6 @@ describe('Integration', () => {
}));
it('should correctly use the preserve strategy', fakeAsync(() => {
@Component({
selector: 'someRoot',
template:
@ -1877,7 +1892,6 @@ describe('Integration', () => {
}));
it('should correctly use the merge strategy', fakeAsync(() => {
@Component({
selector: 'someRoot',
template:
@ -1905,8 +1919,7 @@ describe('Integration', () => {
path: 'team/:id',
component: TeamCmp,
children: [
{path: 'link', component: StringLinkButtonCmp},
{path: 'simple', component: SimpleCmp}
{path: 'link', component: StringLinkButtonCmp}, {path: 'simple', component: SimpleCmp}
]
}]);
@ -1928,9 +1941,8 @@ describe('Integration', () => {
router.resetConfig([{
path: 'team/:id',
component: TeamCmp,
children: [
{path: 'link', component: AbsoluteLinkCmp}, {path: 'simple', component: SimpleCmp}
]
children:
[{path: 'link', component: AbsoluteLinkCmp}, {path: 'simple', component: SimpleCmp}]
}]);
router.navigateByUrl('/team/22/link');
@ -1951,9 +1963,8 @@ describe('Integration', () => {
router.resetConfig([{
path: 'team/:id',
component: TeamCmp,
children: [
{path: 'link', component: RelativeLinkCmp}, {path: 'simple', component: SimpleCmp}
]
children:
[{path: 'link', component: RelativeLinkCmp}, {path: 'simple', component: SimpleCmp}]
}]);
router.navigateByUrl('/team/22/link');
@ -2019,23 +2030,31 @@ describe('Integration', () => {
expect(location.path()).toEqual('/team/22/simple?q=1#f');
})));
it('should support history state',
fakeAsync(inject([Router, Location], (router: Router, location: SpyLocation) => {
describe('should support history and state', () => {
let component: typeof LinkWithState|typeof DivLinkWithState;
it('for anchor elements', () => {
// Test logic in afterEach to reduce duplication
component = LinkWithState;
});
it('for non-anchor elements', () => {
// Test logic in afterEach to reduce duplication
component = DivLinkWithState;
});
afterEach(fakeAsync(inject([Router, Location], (router: Router, location: SpyLocation) => {
const fixture = createRoot(router, RootCmp);
router.resetConfig([{
path: 'team/:id',
component: TeamCmp,
children: [
{path: 'link', component: LinkWithState}, {path: 'simple', component: SimpleCmp}
]
children: [{path: 'link', component}, {path: 'simple', component: SimpleCmp}]
}]);
router.navigateByUrl('/team/22/link');
advance(fixture);
const native = fixture.nativeElement.querySelector('a');
expect(native.getAttribute('href')).toEqual('/team/22/simple');
const native = fixture.nativeElement.querySelector('#link');
native.click();
advance(fixture);
@ -2043,11 +2062,10 @@ describe('Integration', () => {
// Check the history entry
const history = (location as any)._history;
expect(history[history.length - 1].state.foo).toBe('bar');
expect(history[history.length - 1].state)
.toEqual({foo: 'bar', navigationId: history.length});
})));
});
it('should set href on area elements', fakeAsync(() => {
@Component({
@ -2232,7 +2250,9 @@ describe('Integration', () => {
}
}
beforeEach(() => { TestBed.configureTestingModule({providers: [AlwaysTrue]}); });
beforeEach(() => {
TestBed.configureTestingModule({providers: [AlwaysTrue]});
});
it('works', fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
const fixture = createRoot(router, RootCmp);
@ -2253,7 +2273,9 @@ describe('Integration', () => {
providers: [{
provide: 'CanActivate',
useValue: (a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => {
return Observable.create((observer: any) => { observer.next(false); });
return Observable.create((observer: any) => {
observer.next(false);
});
}
}]
});
@ -2310,7 +2332,9 @@ describe('Integration', () => {
TestBed.configureTestingModule({
providers: [{
provide: 'alwaysFalse',
useValue: (a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => { return false; }
useValue: (a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => {
return false;
}
}]
});
});
@ -2330,7 +2354,6 @@ describe('Integration', () => {
location.go('/two');
advance(fixture);
expect(location.path()).toEqual('/one');
})));
});
@ -2368,12 +2391,16 @@ describe('Integration', () => {
providers: [
{
provide: 'returnUrlTree',
useFactory: (router: Router) => () => { return router.parseUrl('/redirected'); },
useFactory: (router: Router) => () => {
return router.parseUrl('/redirected');
},
deps: [Router]
},
{
provide: 'returnRootUrlTree',
useFactory: (router: Router) => () => { return router.parseUrl('/'); },
useFactory: (router: Router) => () => {
return router.parseUrl('/');
},
deps: [Router]
}
]
@ -2492,7 +2519,9 @@ describe('Integration', () => {
{path: 'redirected', component: SimpleCmp}
]);
const fixture = createRoot(router, RootCmp);
router.navigateByUrl('/one').then(v => { resolvedPath = location.path(); });
router.navigateByUrl('/one').then(v => {
resolvedPath = location.path();
});
tick();
expect(resolvedPath).toBe('/redirected');
@ -2541,7 +2570,8 @@ describe('Integration', () => {
},
{
path: 'd/:param',
component: WrapperCmp, runGuardsAndResolvers,
component: WrapperCmp,
runGuardsAndResolvers,
children: [
{
path: 'e/:param',
@ -2889,8 +2919,9 @@ describe('Integration', () => {
},
{
provide: 'alwaysFalse',
useValue:
(c: any, a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => { return false; }
useValue: (c: any, a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => {
return false;
}
},
{
provide: 'alwaysFalseAndLogging',
@ -3143,7 +3174,8 @@ describe('Integration', () => {
providers: [
ClassWithNextState, {
provide: 'FunctionWithNextState',
useValue: (cmp: any, currentRoute: ActivatedRouteSnapshot,
useValue:
(cmp: any, currentRoute: ActivatedRouteSnapshot,
currentState: RouterStateSnapshot, nextState: RouterStateSnapshot) => {
log.push(currentState.url, nextState.url);
return true;
@ -3198,7 +3230,9 @@ describe('Integration', () => {
}
}
beforeEach(() => { TestBed.configureTestingModule({providers: [AlwaysTrue]}); });
beforeEach(() => {
TestBed.configureTestingModule({providers: [AlwaysTrue]});
});
it('works', fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
const fixture = createRoot(router, RootCmp);
@ -3223,7 +3257,9 @@ describe('Integration', () => {
providers: [{
provide: 'CanDeactivate',
useValue: (c: TeamCmp, a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => {
return Observable.create((observer: any) => { observer.next(false); });
return Observable.create((observer: any) => {
observer.next(false);
});
}
}]
});
@ -3282,7 +3318,6 @@ describe('Integration', () => {
fakeAsync(inject(
[Router, Location, NgModuleFactoryLoader],
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
@Component({selector: 'admin', template: '<router-outlet></router-outlet>'})
class AdminComponent {
}
@ -3350,7 +3385,6 @@ describe('Integration', () => {
fakeAsync(inject(
[Router, Location, NgModuleFactoryLoader],
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
@Component({selector: 'lazy', template: 'lazy-loaded'})
class LazyLoadedComponent {
}
@ -3418,7 +3452,6 @@ describe('Integration', () => {
it('should support navigating from within the guard',
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
const fixture = createRoot(router, RootCmp);
router.resetConfig([
@ -3454,7 +3487,6 @@ describe('Integration', () => {
fakeAsync(inject(
[Router, Location, NgModuleFactoryLoader],
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
@Component({selector: 'lazy', template: 'lazy-loaded'})
class LazyLoadedComponent {
}
@ -3477,21 +3509,23 @@ describe('Integration', () => {
let navFalseResult: any;
let navTrueResult: any;
router.navigateByUrl('/lazy-false').then(v => { navFalseResult = v; });
router.navigateByUrl('/lazy-false').then(v => {
navFalseResult = v;
});
advance(fixture);
router.navigateByUrl('/lazy-true').then(v => { navTrueResult = v; });
router.navigateByUrl('/lazy-true').then(v => {
navTrueResult = v;
});
advance(fixture);
expect(navFalseResult).toBe(false);
expect(navTrueResult).toBe(true);
})));
it('should execute CanLoad only once',
fakeAsync(inject(
[Router, Location, NgModuleFactoryLoader],
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
@Component({selector: 'lazy', template: 'lazy-loaded'})
class LazyLoadedComponent {
}
@ -3526,10 +3560,11 @@ describe('Integration', () => {
});
describe('order', () => {
class Logger {
logs: string[] = [];
add(thing: string) { this.logs.push(thing); }
add(thing: string) {
this.logs.push(thing);
}
}
beforeEach(() => {
@ -3674,7 +3709,6 @@ describe('Integration', () => {
advance(fixture);
expect(navigateSpy.calls.mostRecent().args[1].queryParams);
})));
});
@ -3689,8 +3723,7 @@ describe('Integration', () => {
children: [{
path: 'link',
component: DummyLinkCmp,
children:
[{path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp}]
children: [{path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp}]
}]
}]);
@ -3745,8 +3778,7 @@ describe('Integration', () => {
children: [{
path: 'link',
component: DummyLinkWithParentCmp,
children:
[{path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp}]
children: [{path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp}]
}]
}]);
@ -3774,8 +3806,7 @@ describe('Integration', () => {
children: [{
path: 'link',
component: DummyLinkCmp,
children:
[{path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp}]
children: [{path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp}]
}]
}]);
@ -3831,7 +3862,6 @@ describe('Integration', () => {
advance(fixture);
expect(paragraph.textContent).toEqual('false');
}));
});
describe('lazy loading', () => {
@ -3989,7 +4019,9 @@ describe('Integration', () => {
})
class LoadedModule {
static instances = 0;
constructor() { LoadedModule.instances++; }
constructor() {
LoadedModule.instances++;
}
}
loader.stubbedModules = {expected: LoadedModule};
@ -4178,7 +4210,6 @@ describe('Integration', () => {
it('should allow lazy loaded module in named outlet',
fakeAsync(inject(
[Router, NgModuleFactoryLoader], (router: Router, loader: SpyNgModuleFactoryLoader) => {
@Component({selector: 'lazy', template: 'lazy-loaded'})
class LazyComponent {
}
@ -4218,7 +4249,6 @@ describe('Integration', () => {
it('should allow componentless named outlet to render children',
fakeAsync(inject(
[Router, NgModuleFactoryLoader], (router: Router, loader: SpyNgModuleFactoryLoader) => {
const fixture = createRoot(router, RootCmp);
router.resetConfig([{
@ -4478,7 +4508,6 @@ describe('Integration', () => {
expect(secondConfig).toBeDefined();
expect(secondConfig.routes[0].path).toEqual('LoadedModule2');
})));
});
describe('custom url handling strategies', () => {
@ -4528,9 +4557,8 @@ describe('Integration', () => {
router.resetConfig([{
path: 'include',
component: TeamCmp,
children: [
{path: 'user/:name', component: UserCmp}, {path: 'simple', component: SimpleCmp}
]
children:
[{path: 'user/:name', component: UserCmp}, {path: 'simple', component: SimpleCmp}]
}]);
const events: any[] = [];
@ -4592,9 +4620,8 @@ describe('Integration', () => {
router.resetConfig([{
path: 'include',
component: TeamCmp,
children: [
{path: 'user/:name', component: UserCmp}, {path: 'simple', component: SimpleCmp}
]
children:
[{path: 'user/:name', component: UserCmp}, {path: 'simple', component: SimpleCmp}]
}]);
const events: any[] = [];
@ -4707,10 +4734,16 @@ describe('Integration', () => {
}
class ShortLifecycle implements RouteReuseStrategy {
shouldDetach(route: ActivatedRouteSnapshot): boolean { return false; }
shouldDetach(route: ActivatedRouteSnapshot): boolean {
return false;
}
store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void {}
shouldAttach(route: ActivatedRouteSnapshot): boolean { return false; }
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle|null { return null; }
shouldAttach(route: ActivatedRouteSnapshot): boolean {
return false;
}
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle|null {
return null;
}
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
if (future.routeConfig !== curr.routeConfig) {
return false;
@ -4804,7 +4837,9 @@ describe('Integration', () => {
!!router.parseUrl(router.url).root.children['toolpanel']);
}
public ngOnDestroy(): void { this.subscription.unsubscribe(); }
public ngOnDestroy(): void {
this.subscription.unsubscribe();
}
}
@Component({selector: 'tool-1-cmp', template: 'Tool 1 showing'})
@ -4876,7 +4911,6 @@ describe('Testing router options', () => {
});
describe('malformedUriErrorHandler', () => {
function malformedUriErrorHandler(e: URIError, urlSerializer: UrlSerializer, url: string) {
return urlSerializer.parse('/error');
}
@ -4951,11 +4985,18 @@ class LinkWithQueryParamsAndFragment {
@Component({
selector: 'link-cmp',
template: `<a [routerLink]="['../simple']" [state]="{foo: 'bar'}">link</a>`
template: `<a id="link" [routerLink]="['../simple']" [state]="{foo: 'bar'}">link</a>`
})
class LinkWithState {
}
@Component({
selector: 'div-link-cmp',
template: `<div id="link" [routerLink]="['../simple']" [state]="{foo: 'bar'}">link</div>`
})
class DivLinkWithState {
}
@Component({selector: 'simple-cmp', template: `simple`})
class SimpleCmp {
}
@ -5078,7 +5119,9 @@ class OutletInNgIf {
})
class DummyLinkWithParentCmp {
private exact: boolean;
constructor(route: ActivatedRoute) { this.exact = (<any>route.snapshot.params).exact === 'true'; }
constructor(route: ActivatedRoute) {
this.exact = (<any>route.snapshot.params).exact === 'true';
}
}
@Component({selector: 'cmp', template: ''})
@ -5100,7 +5143,9 @@ class RootCmp {
class RootCmpWithOnInit {
constructor(private router: Router) {}
ngOnInit(): void { this.router.navigate(['one']); }
ngOnInit(): void {
this.router.navigate(['one']);
}
}
@Component({
@ -5117,7 +5162,9 @@ class RootCmpWithNamedOutlet {
@Component({selector: 'throwing-cmp', template: ''})
class ThrowingCmp {
constructor() { throw new Error('Throwing Cmp'); }
constructor() {
throw new Error('Throwing Cmp');
}
}
@ -5155,6 +5202,7 @@ class LazyComponent {
RelativeLinkCmp,
DummyLinkWithParentCmp,
LinkWithQueryParamsAndFragment,
DivLinkWithState,
LinkWithState,
CollectParamsCmp,
QueryParamsAndFragmentCmp,
@ -5185,6 +5233,7 @@ class LazyComponent {
RelativeLinkCmp,
DummyLinkWithParentCmp,
LinkWithQueryParamsAndFragment,
DivLinkWithState,
LinkWithState,
CollectParamsCmp,
QueryParamsAndFragmentCmp,
@ -5217,6 +5266,7 @@ class LazyComponent {
RelativeLinkCmp,
DummyLinkWithParentCmp,
LinkWithQueryParamsAndFragment,
DivLinkWithState,
LinkWithState,
CollectParamsCmp,
QueryParamsAndFragmentCmp,