fix(router): fix index routes
This commit is contained in:
@ -1,9 +1,8 @@
|
||||
import {DefaultUrlSerializer} from '../src/url_serializer';
|
||||
import {UrlTree, UrlSegment} from '../src/url_tree';
|
||||
import {ActivatedRoute} from '../src/router_state';
|
||||
import {ActivatedRoute, ActivatedRouteSnapshot} from '../src/router_state';
|
||||
import {PRIMARY_OUTLET, Params} from '../src/shared';
|
||||
import {createUrlTree} from '../src/create_url_tree';
|
||||
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
|
||||
|
||||
describe('createUrlTree', () => {
|
||||
const serializer = new DefaultUrlSerializer();
|
||||
@ -175,6 +174,7 @@ function create(start: UrlSegment | null, tree: UrlTree, commands: any[], queryP
|
||||
if (!start) {
|
||||
expect(start).toBeDefined();
|
||||
}
|
||||
const a = new ActivatedRoute(new BehaviorSubject([start]), <any>null, PRIMARY_OUTLET, "someComponent", null);
|
||||
const s = new ActivatedRouteSnapshot([], <any>null, PRIMARY_OUTLET, "someComponent", null, start);
|
||||
const a = new ActivatedRoute(<any>null, <any>null, PRIMARY_OUTLET, "someComponent", s);
|
||||
return createUrlTree(a, tree, commands, queryParameters, fragment);
|
||||
}
|
@ -112,11 +112,31 @@ describe('recognize', () => {
|
||||
});
|
||||
|
||||
describe("index", () => {
|
||||
it("should support index routes", () => {
|
||||
it("should support root index routes", () => {
|
||||
recognize(RootComponent, [
|
||||
{index: true, component: ComponentA}
|
||||
], tree("")).forEach(s => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
});
|
||||
});
|
||||
|
||||
it("should support nested root index routes", () => {
|
||||
recognize(RootComponent, [
|
||||
{index: true, component: ComponentA, children: [{index: true, component: ComponentB}]}
|
||||
], tree("")).forEach(s => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
});
|
||||
});
|
||||
|
||||
it("should support index routes", () => {
|
||||
recognize(RootComponent, [
|
||||
{path: 'a', component: ComponentA, children: [
|
||||
{index: true, component: ComponentB}
|
||||
]}
|
||||
], tree("a")).forEach(s => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
});
|
||||
});
|
||||
|
||||
@ -137,6 +157,15 @@ describe('recognize', () => {
|
||||
s.firstChild(<any>s.firstChild(<any>s.firstChild(s.root))), "c/10", {id: '10'}, ComponentC);
|
||||
});
|
||||
});
|
||||
|
||||
it("should pass parameters to every nested index route (case with non-index route)", () => {
|
||||
recognize(RootComponent, [
|
||||
{path: 'a', component: ComponentA, children: [{index: true, component: ComponentB}]}
|
||||
], tree("/a;a=1")).forEach(s => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "a", {a: '1'}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {a: '1'}, ComponentB);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("wildcards", () => {
|
||||
@ -198,7 +227,7 @@ describe('recognize', () => {
|
||||
|
||||
function checkActivatedRoute(actual: ActivatedRouteSnapshot | null, url: string, params: Params, cmp: Function, outlet: string = PRIMARY_OUTLET):void {
|
||||
if (actual === null) {
|
||||
expect(actual).toBeDefined();
|
||||
expect(actual).not.toBeNull();
|
||||
} else {
|
||||
expect(actual.urlSegments.map(s => s.path).join("/")).toEqual(url);
|
||||
expect(actual.params).toEqual(params);
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {Component, Injector} from '@angular/core';
|
||||
import {
|
||||
describe,
|
||||
ddescribe,
|
||||
it,
|
||||
iit,
|
||||
xit,
|
||||
@ -199,6 +200,26 @@ describe("Integration", () => {
|
||||
expect(user.recordedParams).toEqual([{name: 'victor'}, {name: 'fedor'}]);
|
||||
})));
|
||||
|
||||
it('should work when navigating to /',
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb:TestComponentBuilder) => {
|
||||
router.resetConfig([
|
||||
{ index: true, component: SimpleCmp },
|
||||
{ path: '/user/:name', component: UserCmp }
|
||||
]);
|
||||
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
|
||||
router.navigateByUrl('/user/victor');
|
||||
advance(fixture);
|
||||
|
||||
expect(fixture.debugElement.nativeElement).toHaveText('user victor');
|
||||
|
||||
router.navigateByUrl('/');
|
||||
advance(fixture);
|
||||
|
||||
expect(fixture.debugElement.nativeElement).toHaveText('simple');
|
||||
})));
|
||||
|
||||
describe("router links", () => {
|
||||
it("should support string router links",
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
|
||||
|
Reference in New Issue
Block a user