Skip to content

Commit

Permalink
[added] <DefaultRoute name>
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Aug 29, 2014
1 parent 6fdaefe commit 79caf99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions modules/components/DefaultRoute.js
Expand Up @@ -10,8 +10,8 @@ var Route = require('./Route');
function DefaultRoute(props) {
return Route(
merge(props, {
name: null,
path: null
path: null,
isDefault: true
})
);
}
Expand Down
14 changes: 4 additions & 10 deletions modules/stores/RouteStore.js
Expand Up @@ -48,19 +48,13 @@ var RouteStore = {
props.name || props.path
);

if ((props.path || props.name) && !props.catchAll) {
if ((props.path || props.name) && !props.isDefault && !props.catchAll) {
props.path = Path.normalize(props.path || props.name);
} else if (parentRoute) {
// <Routes> have no path prop.
props.path = parentRoute.props.path || '/';
} else {
props.path = (parentRoute && parentRoute.props.path) || '/';

if (props.catchAll) {
if (props.catchAll)
props.path += '*';
} else if (!props.children) {
props.isDefault = true;
}
} else {
props.path = '/';
}

props.paramNames = Path.extractParamNames(props.path);
Expand Down
13 changes: 13 additions & 0 deletions specs/DefaultRoute.spec.js
Expand Up @@ -37,6 +37,19 @@ describe('when registering a DefaultRoute', function () {
RouteStore.unregisterRoute(defaultRoute);
});
});

describe('that has a name', function () {
it('is able to be looked up by name', function () {
var defaultRoute;
var routes = Routes({ handler: App },
defaultRoute = DefaultRoute({ name: 'home', handler: App })
);

RouteStore.registerRoute(defaultRoute, routes);
expect(RouteStore.getRouteByName('home')).toBe(defaultRoute);
RouteStore.unregisterRoute(defaultRoute);
});
});
});

describe('when no child routes match a URL, but the parent matches', function () {
Expand Down

0 comments on commit 79caf99

Please sign in to comment.