Skip to content
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

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just check if it's a string with a typeof operator


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 () {
posva marked this conversation as resolved.
Show resolved Hide resolved
process.env.NODE_ENV = 'development'
const { path } = match(
{ name: 'error', params: { pathMatch: '' }},
routes[0]
)
expect(console.warn).not.toHaveBeenCalled()
expect(path).toEqual('/error/')
posva marked this conversation as resolved.
Show resolved Hide resolved
})
})