Skip to content

Commit 6df5320

Browse files
taiontimdorr
authored andcommitted
Properly continue match after pathless routes (#3308)
1 parent b5175b1 commit 6df5320

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

modules/__tests__/matchRoutes-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,17 @@ describe('matchRoutes', function () {
346346
done()
347347
})
348348
})
349+
350+
it('supports splat under pathless route at root', function (done) {
351+
const routes = createRoutes(
352+
<Route>
353+
<Route path="*" />
354+
</Route>
355+
)
356+
357+
matchRoutes(routes, createLocation('/'), function (error, match) {
358+
expect(match).toExist()
359+
done()
360+
})
361+
})
349362
})

modules/matchRoutes.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,17 @@ function matchRouteDeep(
8585
paramValues = []
8686
}
8787

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

94-
if (remainingPathname === '' && route.path) {
96+
// By assumption, pattern is non-empty here, which is the prerequisite for
97+
// actually terminating a match.
98+
if (remainingPathname === '') {
9599
const match = {
96100
routes: [ route ],
97101
params: createParams(paramNames, paramValues)
@@ -118,6 +122,7 @@ function matchRouteDeep(
118122
callback(null, match)
119123
}
120124
})
125+
121126
return
122127
}
123128
}

0 commit comments

Comments
 (0)