From 2773281338500431a14e0b3d3d00a00e12ad6327 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Thu, 16 Jun 2016 13:53:34 -0700 Subject: [PATCH] feat(router): drop index property Use path: '/' instead of 'index: true' --- .../@angular/router/src/apply_redirects.ts | 2 +- modules/@angular/router/src/config.ts | 5 -- modules/@angular/router/src/recognize.ts | 2 +- .../@angular/router/test/recognize.spec.ts | 57 ------------------- modules/@angular/router/test/router.spec.ts | 4 +- 5 files changed, 4 insertions(+), 66 deletions(-) diff --git a/modules/@angular/router/src/apply_redirects.ts b/modules/@angular/router/src/apply_redirects.ts index ca9c248e3e..74375db8f6 100644 --- a/modules/@angular/router/src/apply_redirects.ts +++ b/modules/@angular/router/src/apply_redirects.ts @@ -135,7 +135,7 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]): { lastChild: number, 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)) { throw new NoMatch(); } else { diff --git a/modules/@angular/router/src/config.ts b/modules/@angular/router/src/config.ts index 3ca9625b6d..f40b3c4de5 100644 --- a/modules/@angular/router/src/config.ts +++ b/modules/@angular/router/src/config.ts @@ -3,11 +3,6 @@ import {Type} from '@angular/core'; export type RouterConfig = Route[]; export interface Route { - /** - * Use `path: ''` instead. - * @deprecated - */ - index?: boolean; path?: string; terminal?: boolean; component?: Type|string; diff --git a/modules/@angular/router/src/recognize.ts b/modules/@angular/router/src/recognize.ts index bb2a2017b3..bb6c394e5c 100644 --- a/modules/@angular/router/src/recognize.ts +++ b/modules/@angular/router/src/recognize.ts @@ -111,7 +111,7 @@ function processPathsWithParamsAgainstRoute( } 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)) { throw new NoMatch(); } else { diff --git a/modules/@angular/router/test/recognize.spec.ts b/modules/@angular/router/test/recognize.spec.ts index adaeb86201..de619fde73 100644 --- a/modules/@angular/router/test/recognize.spec.ts +++ b/modules/@angular/router/test/recognize.spec.ts @@ -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(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(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(s.firstChild(s.root)), "", {}, ComponentB); - checkActivatedRoute( - s.firstChild(s.firstChild(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(s.firstChild(s.root)), "", {a: '1'}, ComponentB); - }); - }); - }); - describe("matching empty url", () => { it("should support root index routes", () => { recognize(RootComponent, [ diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts index 3c2b93674b..dd60a79b20 100644 --- a/modules/@angular/router/test/router.spec.ts +++ b/modules/@angular/router/test/router.spec.ts @@ -259,9 +259,9 @@ describe("Integration", () => { fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => { const fixture = tcb.createFakeAsync(RootCmp); advance(fixture); - + router.resetConfig([ - { index: true, component: SimpleCmp }, + { path: '', terminal: true, component: SimpleCmp }, { path: '/user/:name', component: UserCmp } ]);