From 7e12208ca64b680516f3b5fe62d160f9e5425366 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Thu, 16 Jun 2016 14:14:09 -0700 Subject: [PATCH] feat(router): do not support paths starting with / --- modules/@angular/router/src/apply_redirects.ts | 4 ++-- modules/@angular/router/src/recognize.ts | 4 ++-- modules/@angular/router/test/recognize.spec.ts | 2 +- modules/@angular/router/test/router.spec.ts | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/@angular/router/src/apply_redirects.ts b/modules/@angular/router/src/apply_redirects.ts index 74375db8f6..69b3ca64b1 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.path === '' || route.path === '/') { + if (route.path === '') { if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) { throw new NoMatch(); } else { @@ -143,7 +143,7 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]): { } } - const path = route.path.startsWith('/') ? route.path.substring(1) : route.path; + const path = route.path; const parts = path.split('/'); const positionalParamSegments: {[k: string]: UrlPathWithParams} = {}; const consumedPaths: UrlPathWithParams[] = []; diff --git a/modules/@angular/router/src/recognize.ts b/modules/@angular/router/src/recognize.ts index bb6c394e5c..1b11fcb34b 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.path === '' || route.path === '/') { + if (route.path === '') { if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) { throw new NoMatch(); } else { @@ -119,7 +119,7 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) { } } - const path = route.path.startsWith('/') ? route.path.substring(1) : route.path; + const path = route.path; const parts = path.split('/'); const posParameters: {[key: string]: any} = {}; const consumedPaths: UrlPathWithParams[] = []; diff --git a/modules/@angular/router/test/recognize.spec.ts b/modules/@angular/router/test/recognize.spec.ts index de619fde73..73ff4b0354 100644 --- a/modules/@angular/router/test/recognize.spec.ts +++ b/modules/@angular/router/test/recognize.spec.ts @@ -55,7 +55,7 @@ describe('recognize', () => { it('should set url segment and index properly (nested case)', () => { const url = tree("a/b/c"); recognize(RootComponent, [ - { path: '/a/b', component: ComponentA, children: [ + { path: 'a/b', component: ComponentA, children: [ {path: 'c', component: ComponentC} ] }, ], url, "a/b/c").subscribe((s:RouterStateSnapshot) => { diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts index dd60a79b20..4cde4d7cb7 100644 --- a/modules/@angular/router/test/router.spec.ts +++ b/modules/@angular/router/test/router.spec.ts @@ -262,7 +262,7 @@ describe("Integration", () => { router.resetConfig([ { path: '', terminal: true, component: SimpleCmp }, - { path: '/user/:name', component: UserCmp } + { path: 'user/:name', component: UserCmp } ]); router.navigateByUrl('/user/victor'); @@ -282,7 +282,7 @@ describe("Integration", () => { advance(fixture); router.resetConfig([ - { path: '/user/:name', component: UserCmp } + { path: 'user/:name', component: UserCmp } ]); const recordedEvents:any = []; @@ -324,7 +324,7 @@ describe("Integration", () => { advance(fixture); router.resetConfig([ - { path: '/user/:name', component: UserCmp } + { path: 'user/:name', component: UserCmp } ]); const recordedEvents:any = []; @@ -492,8 +492,8 @@ describe("Integration", () => { advance(fixture); router.resetConfig([ - { path: '/old/team/:id', redirectTo: 'team/:id' }, - { path: '/team/:id', component: TeamCmp } + { path: 'old/team/:id', redirectTo: 'team/:id' }, + { path: 'team/:id', component: TeamCmp } ]); router.navigateByUrl('old/team/22'); @@ -639,7 +639,7 @@ describe("Integration", () => { router.resetConfig([ { path: 'team/:id', component: TeamCmp, children: [ - {path: '/', terminal: true, component: SimpleCmp}, + {path: '', terminal: true, component: SimpleCmp}, {path: 'user/:name', component: UserCmp, canDeactivate: ["CanDeactivateUser"] } ]} ]);