From da70364cfcdc49a0558807e09f3a7bd0140ddd5f Mon Sep 17 00:00:00 2001 From: Mike Ryan Date: Sun, 15 May 2016 20:01:20 -0500 Subject: [PATCH] feat(RouteTraverser): Allow forward slash in nested route paths (#108) Before we ignored nested child routes that contained a forward slash at the beginning of the path. This was to potentially allow for absolute path URLs in nested routes, however there is no way to make this feature work with async route configuration. This change removes this restriction and allows you to add a forward slash at the beginning of the path with no functional difference. --- lib/route-traverser.ts | 27 +-------------------------- spec/route-traverser.spec.ts | 17 ++--------------- 2 files changed, 3 insertions(+), 41 deletions(-) diff --git a/lib/route-traverser.ts b/lib/route-traverser.ts index 248987f..6152809 100644 --- a/lib/route-traverser.ts +++ b/lib/route-traverser.ts @@ -101,12 +101,6 @@ export class RouteTraverser { ): Observable { const pattern = route.path || ''; - if ( pattern.charAt(0) === '/' ) { - remainingPathname = pathname; - paramNames = []; - paramValues = []; - } - return Observable.of(route) .filter(() => remainingPathname !== null) .do(() => { @@ -181,23 +175,4 @@ export class RouteTraverser { export const MATCH_ROUTE_PROVIDERS = [ new Provider(RouteTraverser, { useClass: RouteTraverser }) -]; - - -export function assignParams(paramNames: string[], paramValues: string[]) { - return paramNames.reduce(function (params, paramName, index) { - const paramValue = paramValues && paramValues[index]; - - if ( Array.isArray(params[paramName]) ) { - params[paramName].push(paramValue); - } - else if (paramName in params) { - params[paramName] = [ params[paramName], paramValue ]; - } - else { - params[paramName] = paramValue; - } - - return params; - }, {}); -} +]; \ No newline at end of file diff --git a/spec/route-traverser.spec.ts b/spec/route-traverser.spec.ts index c86870b..3924bc4 100644 --- a/spec/route-traverser.spec.ts +++ b/spec/route-traverser.spec.ts @@ -42,7 +42,7 @@ describe('RouteTraverser', function() { path: '/profile' }, PostRoute = { - path: ':postID' + path: '/:postID' } ] }, @@ -66,7 +66,7 @@ describe('RouteTraverser', function() { path: '/(optional)?', children: [ OptionalRouteChild = { - path: 'child' + path: '/child' } ] }, @@ -346,19 +346,6 @@ describe('RouteTraverser', function() { describe('synchronous route config', function() { describeRoutes(); - - xdescribe('when the location matches a nested absolute route', function() { - it('matches the correct routes', function(done) { - traverser - .find(change('/team')) - .subscribe(match => { - expect(match).toBeDefined(); - expect(match.routes).toEqual([ RootRoute, UsersRoute, TeamRoute ]); - - done(); - }); - }); - }); }); describe('asynchronous route config', function() {