Skip to content

fix: correctly calculate path when pathMatch is empty string (fix #3106) #3111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/util/params.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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('/')
})
})