fix(router): top-levels do not work in ngIf

This commit is contained in:
vsavkin 2016-06-26 11:52:32 -07:00
parent 855f3afb28
commit d20488752b
5 changed files with 44 additions and 11 deletions

View File

@ -28,7 +28,7 @@ import {UrlChangeListener} from './platform_location';
* @stable
*/
export abstract class LocationStrategy {
abstract path(includeHash: boolean): string;
abstract path(includeHash?: boolean): string;
abstract prepareExternalUrl(internal: string): string;
abstract pushState(state: any, title: string, url: string, queryParams: string): void;
abstract replaceState(state: any, title: string, url: string, queryParams: string): void;

View File

@ -276,7 +276,7 @@ export class Router {
return new Promise((resolvePromise, rejectPromise) => {
let updatedUrl: UrlTree;
let state: RouterState;
let navigationIsSuccessful;
let navigationIsSuccessful: boolean;
applyRedirects(url, this.config)
.mergeMap(u => {
updatedUrl = u;
@ -494,6 +494,7 @@ class ActivateRoutes {
const currRoot = this.currState ? this.currState._root : null;
pushQueryParamsAndFragment(this.futureState);
advanceActivatedRoute(this.futureState.root);
this.activateChildRoutes(futureRoot, currRoot, parentOutletMap);
}

View File

@ -518,10 +518,28 @@ describe('Integration', () => {
it('should support top-level link',
fakeAsync(
inject([Router, TestComponentBuilder], (router: Router, tcb: TestComponentBuilder) => {
let fixture = tcb.createFakeAsync(AbsoluteLinkCmp);
const fixture = tcb.createFakeAsync(RelativeLinkInIfCmp);
advance(fixture);
expect(fixture.debugElement.nativeElement).toHaveText('link');
router.resetConfig(
[{path: 'simple', component: SimpleCmp}, {path: '', component: BlankCmp}]);
router.navigateByUrl('/');
advance(fixture);
expect(fixture.debugElement.nativeElement).toHaveText(' ');
const cmp = fixture.debugElement.componentInstance;
cmp.show = true;
advance(fixture);
expect(fixture.debugElement.nativeElement).toHaveText('link ');
const native = fixture.debugElement.nativeElement.querySelector('a');
expect(native.getAttribute('href')).toEqual('/simple');
native.click();
advance(fixture);
expect(fixture.debugElement.nativeElement).toHaveText('link simple');
})));
it('should support query params and fragments',
@ -731,13 +749,13 @@ describe('Integration', () => {
advance(fixture);
expect(location.path()).toEqual('/team/22');
let successStatus;
let successStatus: boolean;
router.navigateByUrl('/team/33').then(res => successStatus = res);
advance(fixture);
expect(location.path()).toEqual('/team/33');
expect(successStatus).toEqual(true);
let canceledStatus;
let canceledStatus: boolean;
router.navigateByUrl('/team/44').then(res => canceledStatus = res);
advance(fixture);
expect(location.path()).toEqual('/team/33');
@ -1017,6 +1035,16 @@ class DummyLinkWithParentCmp {
class RelativeLinkCmp {
}
@Component({
selector: 'link-cmp',
template:
`<div *ngIf="show"><a [routerLink]="['./simple']">link</a></div> <router-outlet></router-outlet>`,
directives: ROUTER_DIRECTIVES
})
class RelativeLinkInIfCmp {
show: boolean = false;
}
@Component({
selector: 'link-cmp',
template: `<a [routerLink]="['../simple']" [queryParams]="{q: '1'}" fragment="f">link</a>`,
@ -1040,7 +1068,9 @@ class CollectParamsCmp {
a.url.forEach(u => this.urls.push(u));
}
recordedUrls(): string[] { return this.urls.map(a => a.map(p => p.path).join('/')); }
recordedUrls(): string[] {
return this.urls.map((a: any) => a.map((p: any) => p.path).join('/'));
}
}
@Component({selector: 'blank-cmp', template: ``, directives: ROUTER_DIRECTIVES})

View File

@ -8,6 +8,8 @@
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"outDir": "../../../dist/all/@angular/router/",
"paths": {
"@angular/*": ["../../../dist/all/@angular/*"]

View File

@ -197,7 +197,7 @@ export declare class HashLocationStrategy extends LocationStrategy {
forward(): void;
getBaseHref(): string;
onPopState(fn: UrlChangeListener): void;
path(): string;
path(includeHash?: boolean): string;
prepareExternalUrl(internal: string): string;
pushState(state: any, title: string, path: string, queryParams: string): void;
replaceState(state: any, title: string, path: string, queryParams: string): void;
@ -231,7 +231,7 @@ export declare class Location {
go(path: string, query?: string): void;
isCurrentPathEqualTo(path: string, query?: string): boolean;
normalize(url: string): string;
path(): string;
path(includeHash?: boolean): string;
prepareExternalUrl(url: string): string;
replaceState(path: string, query?: string): void;
subscribe(onNext: (value: any) => void, onThrow?: (exception: any) => void, onReturn?: () => void): Object;
@ -246,7 +246,7 @@ export declare abstract class LocationStrategy {
abstract forward(): void;
abstract getBaseHref(): string;
abstract onPopState(fn: UrlChangeListener): void;
abstract path(): string;
abstract path(includeHash?: boolean): string;
abstract prepareExternalUrl(internal: string): string;
abstract pushState(state: any, title: string, url: string, queryParams: string): void;
abstract replaceState(state: any, title: string, url: string, queryParams: string): void;
@ -495,7 +495,7 @@ export declare class PathLocationStrategy extends LocationStrategy {
forward(): void;
getBaseHref(): string;
onPopState(fn: UrlChangeListener): void;
path(): string;
path(includeHash?: boolean): string;
prepareExternalUrl(internal: string): string;
pushState(state: any, title: string, url: string, queryParams: string): void;
replaceState(state: any, title: string, url: string, queryParams: string): void;