Skip to content

Commit 79caf99

Browse files
committed
[added] <DefaultRoute name>
1 parent 6fdaefe commit 79caf99

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

modules/components/DefaultRoute.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ var Route = require('./Route');
1010
function DefaultRoute(props) {
1111
return Route(
1212
merge(props, {
13-
name: null,
14-
path: null
13+
path: null,
14+
isDefault: true
1515
})
1616
);
1717
}

modules/stores/RouteStore.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,13 @@ var RouteStore = {
4848
props.name || props.path
4949
);
5050

51-
if ((props.path || props.name) && !props.catchAll) {
51+
if ((props.path || props.name) && !props.isDefault && !props.catchAll) {
5252
props.path = Path.normalize(props.path || props.name);
53-
} else if (parentRoute) {
54-
// <Routes> have no path prop.
55-
props.path = parentRoute.props.path || '/';
53+
} else {
54+
props.path = (parentRoute && parentRoute.props.path) || '/';
5655

57-
if (props.catchAll) {
56+
if (props.catchAll)
5857
props.path += '*';
59-
} else if (!props.children) {
60-
props.isDefault = true;
61-
}
62-
} else {
63-
props.path = '/';
6458
}
6559

6660
props.paramNames = Path.extractParamNames(props.path);

specs/DefaultRoute.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ describe('when registering a DefaultRoute', function () {
3737
RouteStore.unregisterRoute(defaultRoute);
3838
});
3939
});
40+
41+
describe('that has a name', function () {
42+
it('is able to be looked up by name', function () {
43+
var defaultRoute;
44+
var routes = Routes({ handler: App },
45+
defaultRoute = DefaultRoute({ name: 'home', handler: App })
46+
);
47+
48+
RouteStore.registerRoute(defaultRoute, routes);
49+
expect(RouteStore.getRouteByName('home')).toBe(defaultRoute);
50+
RouteStore.unregisterRoute(defaultRoute);
51+
});
52+
});
4053
});
4154

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

0 commit comments

Comments
 (0)