Skip to content

Commit 50dabbf

Browse files
committed
fix: correctly calculate path when pathMatch is empty string (vuejs#3106)
1 parent 256cf3e commit 50dabbf

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: 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+
// `params.pathMatch === ''` fixes #3106 so that you can work with location descriptor object having params.pathMatch equal to empty string
24+
if (params.pathMatch || params.pathMatch === '') params[0] = params.pathMatch
2425

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

Diff for: test/unit/specs/create-matcher.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,14 @@ describe('Creating Matcher', function () {
8484
const { params } = match({ path: '/not-found' }, routes[0])
8585
expect(params).toEqual({ pathMatch: '/not-found' })
8686
})
87+
88+
it('calculates correctly and without warning the path of a partial asterisk route with a default param name and pathMatch empty string', function () {
89+
process.env.NODE_ENV = 'development'
90+
const { path } = match(
91+
{ name: 'error', params: { pathMatch: '' }},
92+
routes[0]
93+
)
94+
expect(console.warn).not.toHaveBeenCalled()
95+
expect(path).toEqual('/error/')
96+
})
8797
})

0 commit comments

Comments
 (0)