Skip to content

Commit

Permalink
feat(RouteTraverser): Allow forward slash in nested route paths (#108)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MikeRyanDev authored and brandonroberts committed May 16, 2016
1 parent 407bcee commit da70364
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 41 deletions.
27 changes: 1 addition & 26 deletions lib/route-traverser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ export class RouteTraverser {
): Observable<Match> {
const pattern = route.path || '';

if ( pattern.charAt(0) === '/' ) {
remainingPathname = pathname;
paramNames = [];
paramValues = [];
}

return Observable.of(route)
.filter(() => remainingPathname !== null)
.do(() => {
Expand Down Expand Up @@ -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;
}, {});
}
];
17 changes: 2 additions & 15 deletions spec/route-traverser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('RouteTraverser', function() {
path: '/profile'
},
PostRoute = {
path: ':postID'
path: '/:postID'
}
]
},
Expand All @@ -66,7 +66,7 @@ describe('RouteTraverser', function() {
path: '/(optional)?',
children: [
OptionalRouteChild = {
path: 'child'
path: '/child'
}
]
},
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit da70364

Please sign in to comment.