From 79caf996479ddbc474cbbe2491a938bb0de4aeea Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Thu, 28 Aug 2014 16:43:55 -0700 Subject: [PATCH] [added] --- modules/components/DefaultRoute.js | 4 ++-- modules/stores/RouteStore.js | 14 ++++---------- specs/DefaultRoute.spec.js | 13 +++++++++++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/modules/components/DefaultRoute.js b/modules/components/DefaultRoute.js index 1574d947aa..33cbf211a2 100644 --- a/modules/components/DefaultRoute.js +++ b/modules/components/DefaultRoute.js @@ -10,8 +10,8 @@ var Route = require('./Route'); function DefaultRoute(props) { return Route( merge(props, { - name: null, - path: null + path: null, + isDefault: true }) ); } diff --git a/modules/stores/RouteStore.js b/modules/stores/RouteStore.js index 15ba3b289b..ae8935ec67 100644 --- a/modules/stores/RouteStore.js +++ b/modules/stores/RouteStore.js @@ -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) { - // 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); diff --git a/specs/DefaultRoute.spec.js b/specs/DefaultRoute.spec.js index 23929e946e..5601d18c1a 100644 --- a/specs/DefaultRoute.spec.js +++ b/specs/DefaultRoute.spec.js @@ -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 () {