diff --git a/modules/__tests__/matchRoutes-test.js b/modules/__tests__/matchRoutes-test.js index 23e97ef123..b43574925b 100644 --- a/modules/__tests__/matchRoutes-test.js +++ b/modules/__tests__/matchRoutes-test.js @@ -346,4 +346,17 @@ describe('matchRoutes', function () { done() }) }) + + it('supports splat under pathless route at root', function (done) { + const routes = createRoutes( + + + + ) + + matchRoutes(routes, createLocation('/'), function (error, match) { + expect(match).toExist() + done() + }) + }) }) diff --git a/modules/matchRoutes.js b/modules/matchRoutes.js index 3c2be8041c..3897d65980 100644 --- a/modules/matchRoutes.js +++ b/modules/matchRoutes.js @@ -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) @@ -118,6 +122,7 @@ function matchRouteDeep( callback(null, match) } }) + return } }