Skip to content

Commit 38e6ccd

Browse files
authored
fix: correctly calculate path when pathMatch is empty string (#3111)
fix #3106
1 parent 256cf3e commit 38e6ccd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/util/params.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export function fillParams (
2020
(regexpCompileCache[path] = Regexp.compile(path))
2121

2222
// Fix #2505 resolving asterisk routes { name: 'not-found', params: { pathMatch: '/not-found' }}
23-
if (params.pathMatch) params[0] = params.pathMatch
23+
// and fix #3106 so that you can work with location descriptor object having params.pathMatch equal to empty string
24+
if (typeof params.pathMatch === 'string') params[0] = params.pathMatch
2425

2526
return filler(params, { pretty: true })
2627
} catch (e) {

test/unit/specs/create-matcher.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,20 @@ describe('Creating Matcher', function () {
8484
const { params } = match({ path: '/not-found' }, routes[0])
8585
expect(params).toEqual({ pathMatch: '/not-found' })
8686
})
87+
88+
it('allows an empty pathMatch', function () {
89+
process.env.NODE_ENV = 'development'
90+
const pathForErrorRoute = match(
91+
{ name: 'error', params: { pathMatch: '' }},
92+
routes[0]
93+
).path
94+
const pathForNotFoundRoute = match(
95+
{ name: 'notFound', params: { pathMatch: '' }},
96+
routes[0]
97+
).path
98+
99+
expect(console.warn).not.toHaveBeenCalled()
100+
expect(pathForErrorRoute).toEqual('/error/')
101+
expect(pathForNotFoundRoute).toEqual('/')
102+
})
87103
})

0 commit comments

Comments
 (0)