{ path: '/', name: 'home', component: components.Home },
{ path: '/%25', name: 'percent', component: components.Home },
{ path: '/to-p/:p', redirect: to => `/p/${to.params.p}` },
- { path: '/p/:p', component: components.Bar },
+ { path: '/p/:p', component: components.Bar, name: 'params' },
]
function createHistory(initialUrl) {
await router.doInitialNavigation()
expect(router.currentRoute).toEqual(
expect.objectContaining({
- name: undefined,
+ name: 'params',
fullPath: encodeURI('/p/€'),
params: { p: '€' },
path: encodeURI('/p/€'),
)
})
+ it('encodes params when resolving', async () => {
+ const history = createHistory('/')
+ const router = new Router({ history, routes })
+ await router.doInitialNavigation()
+ await router.push({ name: 'params', params: { p: '%€' } })
+ expect(router.currentRoute).toEqual(
+ expect.objectContaining({
+ name: 'params',
+ fullPath: encodeURI('/p/%€'),
+ params: { p: '%€' },
+ path: encodeURI('/p/%€'),
+ })
+ )
+ })
+
it('allows navigating to valid unencoded params (IE and Edge)', async () => {
const history = createHistory('/p/€')
const router = new Router({ history, routes })
await router.doInitialNavigation()
expect(router.currentRoute).toEqual(
expect.objectContaining({
- name: undefined,
+ name: 'params',
// unfortunately, we cannot encode the path as we cannot know if it already encoded
// so comparing fullPath and path here is pointless
// fullPath: '/p/€',
spy.mockRestore()
expect(router.currentRoute).toEqual(
expect.objectContaining({
- name: undefined,
+ name: 'params',
// unfortunately, we cannot encode the path as we cannot know if it already encoded
// so comparing fullPath and path here is pointless
// fullPath: '/p/€',