Skip to content

Commit

Permalink
fix: correctly calculate path when pathMatch is empty string (#3111)
Browse files Browse the repository at this point in the history
fix #3106
  • Loading branch information
adi-zz committed Jan 29, 2020
1 parent 256cf3e commit 38e6ccd
Show file tree
Hide file tree
Showing 2 changed files with 18 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
// and fix #3106 so that you can work with location descriptor object having params.pathMatch equal to empty string
if (typeof params.pathMatch === 'string') params[0] = params.pathMatch

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

it('allows an empty pathMatch', function () {
process.env.NODE_ENV = 'development'
const pathForErrorRoute = match(
{ name: 'error', params: { pathMatch: '' }},
routes[0]
).path
const pathForNotFoundRoute = match(
{ name: 'notFound', params: { pathMatch: '' }},
routes[0]
).path

expect(console.warn).not.toHaveBeenCalled()
expect(pathForErrorRoute).toEqual('/error/')
expect(pathForNotFoundRoute).toEqual('/')
})
})

0 comments on commit 38e6ccd

Please sign in to comment.