Skip to content

Commit

Permalink
fix(encoding): keep decoded hash when resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Oct 2, 2020
1 parent 367f063 commit 1a8ffc1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions __tests__/urlEncoding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,17 @@ describe('URL Encoding', () => {
query: { p: '%' },
})
})

it('keeps decoded values in hash', async () => {
// @ts-ignore: override to make the difference
encoding.decode = () => 'd'
// @ts-ignore
encoding.encodeHash = () => '#e'
const router = createRouter()
await router.push({ name: 'home', hash: '#%' })
expect(router.currentRoute.value).toMatchObject({
fullPath: '/#e',
hash: '#%',
})
})
})
4 changes: 2 additions & 2 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export function createRouter(options: RouterOptions): Router {
}

let matchedRoute = matcher.resolve(matcherLocation, currentLocation)
const hash = encodeHash(rawLocation.hash || '')
const hash = rawLocation.hash || ''

if (__DEV__ && hash && !hash.startsWith('#')) {
warn(
Expand All @@ -470,7 +470,7 @@ export function createRouter(options: RouterOptions): Router {
const fullPath = stringifyURL(
stringifyQuery,
assign({}, rawLocation, {
hash,
hash: encodeHash(hash),
path: matchedRoute.path,
})
)
Expand Down

0 comments on commit 1a8ffc1

Please sign in to comment.