feat(router): do not support paths starting with /

This commit is contained in:
vsavkin 2016-06-16 14:14:09 -07:00
parent 2773281338
commit 7e12208ca6
4 changed files with 11 additions and 11 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.path === '' || route.path === '/') { if (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 {
@ -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 parts = path.split('/');
const positionalParamSegments: {[k: string]: UrlPathWithParams} = {}; const positionalParamSegments: {[k: string]: UrlPathWithParams} = {};
const consumedPaths: UrlPathWithParams[] = []; const consumedPaths: UrlPathWithParams[] = [];

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.path === '' || route.path === '/') { if (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 {
@ -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 parts = path.split('/');
const posParameters: {[key: string]: any} = {}; const posParameters: {[key: string]: any} = {};
const consumedPaths: UrlPathWithParams[] = []; const consumedPaths: UrlPathWithParams[] = [];

View File

@ -55,7 +55,7 @@ describe('recognize', () => {
it('should set url segment and index properly (nested case)', () => { it('should set url segment and index properly (nested case)', () => {
const url = tree("a/b/c"); const url = tree("a/b/c");
recognize(RootComponent, [ recognize(RootComponent, [
{ path: '/a/b', component: ComponentA, children: [ { path: 'a/b', component: ComponentA, children: [
{path: 'c', component: ComponentC} {path: 'c', component: ComponentC}
] }, ] },
], url, "a/b/c").subscribe((s:RouterStateSnapshot) => { ], url, "a/b/c").subscribe((s:RouterStateSnapshot) => {

View File

@ -262,7 +262,7 @@ describe("Integration", () => {
router.resetConfig([ router.resetConfig([
{ path: '', terminal: true, component: SimpleCmp }, { path: '', terminal: true, component: SimpleCmp },
{ path: '/user/:name', component: UserCmp } { path: 'user/:name', component: UserCmp }
]); ]);
router.navigateByUrl('/user/victor'); router.navigateByUrl('/user/victor');
@ -282,7 +282,7 @@ describe("Integration", () => {
advance(fixture); advance(fixture);
router.resetConfig([ router.resetConfig([
{ path: '/user/:name', component: UserCmp } { path: 'user/:name', component: UserCmp }
]); ]);
const recordedEvents:any = []; const recordedEvents:any = [];
@ -324,7 +324,7 @@ describe("Integration", () => {
advance(fixture); advance(fixture);
router.resetConfig([ router.resetConfig([
{ path: '/user/:name', component: UserCmp } { path: 'user/:name', component: UserCmp }
]); ]);
const recordedEvents:any = []; const recordedEvents:any = [];
@ -492,8 +492,8 @@ describe("Integration", () => {
advance(fixture); advance(fixture);
router.resetConfig([ router.resetConfig([
{ path: '/old/team/:id', redirectTo: 'team/:id' }, { path: 'old/team/:id', redirectTo: 'team/:id' },
{ path: '/team/:id', component: TeamCmp } { path: 'team/:id', component: TeamCmp }
]); ]);
router.navigateByUrl('old/team/22'); router.navigateByUrl('old/team/22');
@ -639,7 +639,7 @@ describe("Integration", () => {
router.resetConfig([ router.resetConfig([
{ path: 'team/:id', component: TeamCmp, children: [ { path: 'team/:id', component: TeamCmp, children: [
{path: '/', terminal: true, component: SimpleCmp}, {path: '', terminal: true, component: SimpleCmp},
{path: 'user/:name', component: UserCmp, canDeactivate: ["CanDeactivateUser"] } {path: 'user/:name', component: UserCmp, canDeactivate: ["CanDeactivateUser"] }
]} ]}
]); ]);