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
13 changes: 13 additions & 0 deletions modules/__tests__/matchRoutes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,17 @@ describe('matchRoutes', function () {
done()
})
})

it('supports splat under pathless route at root', function (done) {
const routes = createRoutes(
<Route>
<Route path="*" />
</Route>
)

matchRoutes(routes, createLocation('/'), function (error, match) {
expect(match).toExist()
done()
})
})
})
9 changes: 7 additions & 2 deletions modules/matchRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,17 @@ function matchRouteDeep(
paramValues = []
}

if (remainingPathname !== null) {
// Only try to match the path if the route actually has a pattern, and if
// we're not just searching for potential nested absolute paths.
if (remainingPathname !== null && pattern) {
const matched = matchPattern(pattern, remainingPathname)
remainingPathname = matched.remainingPathname
paramNames = [ ...paramNames, ...matched.paramNames ]
paramValues = [ ...paramValues, ...matched.paramValues ]

if (remainingPathname === '' && route.path) {
// By assumption, pattern is non-empty here, which is the prerequisite for
// actually terminating a match.
if (remainingPathname === '') {
const match = {
routes: [ route ],
params: createParams(paramNames, paramValues)
Expand All @@ -118,6 +122,7 @@ function matchRouteDeep(
callback(null, match)
}
})

return
}
}
Expand Down