Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion modules/__tests__/IndexRoute-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,41 @@ describe('An <IndexRoute>', function () {
done()
})
})
})

it('renders when its parents combined pathes match', function (done) {
render((
<Router history={createHistory('/path/test')}>
<Route path="/path" component={Parent}>
<IndexRoute component={Child}/>
<Route path="test" component={Parent}>
<IndexRoute component={Child}/>
</Route>
</Route>
</Router>
), 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((
<Router history={createHistory('/')}>
<Route path="/" component={Parent}>
<Route component={Parent}>
<Route component={Parent}>
<Route component={Parent}>
<Route path="deep" component={Parent}/>
<IndexRoute component={Child}/>
</Route>
</Route>
</Route>
</Route>
</Router>
), node, function () {
expect(node.textContent).toEqual('parent parent parent parent child')
done()
})
})
})
})
21 changes: 20 additions & 1 deletion modules/matchRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
Expand Down