Skip to content

Commit

Permalink
Merge pull request #18 from aivins/multinames
Browse files Browse the repository at this point in the history
Support multiple names for a single route
  • Loading branch information
bryanrsmith committed Feb 26, 2016
2 parents 7f97b08 + 6b5637d commit 38125cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/route-recognizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ export class RouteRecognizer {
let handlers = [{ handler: route.handler, names: names }];

if (routeName) {
this.names[routeName] = {
segments: segments,
handlers: handlers
};
let routeNames = Array.isArray(routeName) ? routeName : [routeName];
for (let i = 0; i < routeNames.length; i++) {
this.names[routeNames[i]] = {
segments: segments,
handlers: handlers
};
}
}

currentState.handlers = handlers;
Expand Down
9 changes: 9 additions & 0 deletions test/route-recognizer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import core from 'core-js';

const staticRoute = {'path': 'static','handler': {'name': 'static'}};
const dynamicRoute = {'path': 'dynamic/:id','handler': {'name': 'dynamic'}};
const multiNameRoute = {'path': 'static','handler': {'name': ['static-multiple', 'static-multiple-alias']}};

const routeTestData = [{
title: 'empty path routes',
Expand Down Expand Up @@ -117,4 +118,12 @@ describe('route recognizer', () => {
expect(recognizer.hasRoute('static')).toBe(true);
expect(recognizer.handlersFor('static')[0].handler).toEqual(staticRoute.handler);
});

it('should find a handler by multiple names', () => {
let recognizer = new RouteRecognizer();
recognizer.add([multiNameRoute]);

expect(recognizer.handlersFor('static-multiple')[0].handler)
.toEqual(recognizer.handlersFor('static-multiple-alias')[0].handler)
});
});

0 comments on commit 38125cd

Please sign in to comment.