Skip to content

Commit

Permalink
Properly continue match after pathless routes (#3308)
Browse files Browse the repository at this point in the history
  • Loading branch information
taion authored and timdorr committed Apr 14, 2016
1 parent b5175b1 commit 6df5320
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit 6df5320

Please sign in to comment.