Skip to content

Commit

Permalink
fix: correctly calculate path when pathMatch is empty string (vue…
Browse files Browse the repository at this point in the history
  • Loading branch information
adi-zz committed Jan 21, 2020
1 parent 256cf3e commit 50dabbf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/util/params.js
Expand Up @@ -20,7 +20,8 @@ export function fillParams (
(regexpCompileCache[path] = Regexp.compile(path))

// Fix #2505 resolving asterisk routes { name: 'not-found', params: { pathMatch: '/not-found' }}
if (params.pathMatch) params[0] = params.pathMatch
// `params.pathMatch === ''` fixes #3106 so that you can work with location descriptor object having params.pathMatch equal to empty string
if (params.pathMatch || params.pathMatch === '') params[0] = params.pathMatch

return filler(params, { pretty: true })
} catch (e) {
Expand Down
10 changes: 10 additions & 0 deletions test/unit/specs/create-matcher.spec.js
Expand Up @@ -84,4 +84,14 @@ describe('Creating Matcher', function () {
const { params } = match({ path: '/not-found' }, routes[0])
expect(params).toEqual({ pathMatch: '/not-found' })
})

it('calculates correctly and without warning the path of a partial asterisk route with a default param name and pathMatch empty string', function () {
process.env.NODE_ENV = 'development'
const { path } = match(
{ name: 'error', params: { pathMatch: '' }},
routes[0]
)
expect(console.warn).not.toHaveBeenCalled()
expect(path).toEqual('/error/')
})
})

0 comments on commit 50dabbf

Please sign in to comment.