diff --git a/modules/__tests__/IndexRoute-test.js b/modules/__tests__/IndexRoute-test.js index 5d4246c349..f55bd24d81 100644 --- a/modules/__tests__/IndexRoute-test.js +++ b/modules/__tests__/IndexRoute-test.js @@ -60,6 +60,41 @@ describe('An ', function () { done() }) }) - }) + it('renders when its parents combined pathes match', function (done) { + render(( + + + + + + + + + ), node, function () { + expect(node.textContent).toEqual('parent parent child') + done() + }) + }) + + it('renders when its parents combined pathes match, and its direct parent is path less', function (done) { + render(( + + + + + + + + + + + + + ), node, function () { + expect(node.textContent).toEqual('parent parent parent parent child') + done() + }) + }) + }) }) diff --git a/modules/matchRoutes.js b/modules/matchRoutes.js index 7a198cde89..58666d66fb 100644 --- a/modules/matchRoutes.js +++ b/modules/matchRoutes.js @@ -21,6 +21,23 @@ function getIndexRoute(route, location, callback) { route.getIndexRoute(location, function (error, indexRoute) { callback(error, !error && createRoutes(indexRoute)[0]) }) + } else if (route.childRoutes) { + const pathless = route.childRoutes.filter(function (obj) { + return !obj.hasOwnProperty('path') + }) + + loopAsync(pathless.length, function (index, next, done) { + getIndexRoute(pathless[index], location, function (error, indexRoute) { + if (error || indexRoute) { + const routes = [ pathless[index] ].concat( Array.isArray(indexRoute) ? indexRoute : [ indexRoute ] ) + done(error, routes) + } else { + next() + } + }) + }, function (err, routes) { + callback(null, routes) + }) } else { callback() } @@ -65,7 +82,9 @@ function matchRouteDeep(basename, route, location, callback) { if (error) { callback(error) } else { - if (indexRoute) + if (Array.isArray(indexRoute)) + match.routes.push(...indexRoute) + else if (indexRoute) match.routes.push(indexRoute) callback(null, match)