feat(router): drop index property

Use path: '/' instead of 'index: true'
This commit is contained in:
vsavkin 2016-06-16 13:53:34 -07:00
parent f8e8d22e4e
commit 2773281338
5 changed files with 4 additions and 66 deletions

View File

@ -135,7 +135,7 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]): {
lastChild: number, lastChild: number,
positionalParamSegments: {[k: string]: UrlPathWithParams} positionalParamSegments: {[k: string]: UrlPathWithParams}
} { } {
if (route.index || route.path === '' || route.path === '/') { if (route.path === '' || route.path === '/') {
if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) { if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) {
throw new NoMatch(); throw new NoMatch();
} else { } else {

View File

@ -3,11 +3,6 @@ import {Type} from '@angular/core';
export type RouterConfig = Route[]; export type RouterConfig = Route[];
export interface Route { export interface Route {
/**
* Use `path: ''` instead.
* @deprecated
*/
index?: boolean;
path?: string; path?: string;
terminal?: boolean; terminal?: boolean;
component?: Type|string; component?: Type|string;

View File

@ -111,7 +111,7 @@ function processPathsWithParamsAgainstRoute(
} }
function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) { function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) {
if (route.index || route.path === '' || route.path === '/') { if (route.path === '' || route.path === '/') {
if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) { if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) {
throw new NoMatch(); throw new NoMatch();
} else { } else {

View File

@ -158,63 +158,6 @@ describe('recognize', () => {
}); });
}); });
describe("index", () => {
it("should support root index routes", () => {
checkRecognize([
{index: true, component: ComponentA}
], "", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
});
});
it("should support nested root index routes", () => {
checkRecognize([
{index: true, component: ComponentA, children: [{index: true, component: ComponentB}]}
], "", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
});
});
it("should support index routes", () => {
checkRecognize([
{path: 'a', component: ComponentA, children: [
{index: true, component: ComponentB}
]}
], "a", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
});
});
it("should support index routes with children", () => {
checkRecognize([
{
index: true, component: ComponentA, children: [
{ index: true, component: ComponentB, children: [
{path: 'c/:id', component: ComponentC}
]
}
]
}
], "c/10", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
checkActivatedRoute(
s.firstChild(<any>s.firstChild(<any>s.firstChild(s.root))), "c/10", {id: '10'}, ComponentC);
});
});
xit("should pass parameters to every nested index route (case with non-index route)", () => {
checkRecognize([
{path: 'a', component: ComponentA, children: [{index: true, component: ComponentB}]}
], "/a;a=1", (s:RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root), "a", {a: '1'}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {a: '1'}, ComponentB);
});
});
});
describe("matching empty url", () => { describe("matching empty url", () => {
it("should support root index routes", () => { it("should support root index routes", () => {
recognize(RootComponent, [ recognize(RootComponent, [

View File

@ -261,7 +261,7 @@ describe("Integration", () => {
advance(fixture); advance(fixture);
router.resetConfig([ router.resetConfig([
{ index: true, component: SimpleCmp }, { path: '', terminal: true, component: SimpleCmp },
{ path: '/user/:name', component: UserCmp } { path: '/user/:name', component: UserCmp }
]); ]);