Skip to content

Commit

Permalink
fix: check query and hash when navigating
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Apr 3, 2020
1 parent b5ee748 commit 3862ad9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
18 changes: 16 additions & 2 deletions __tests__/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ describe('Router', () => {
expect(spy).toHaveBeenCalled()
})

it('navigates to same route record but different query', async () => {
const { router } = await newRouter()
await router.push('/?q=1')
expect(router.currentRoute.value.query).toEqual({ q: '1' })
await router.push('/?q=2')
expect(router.currentRoute.value.query).toEqual({ q: '2' })
})

it('navigates to same route record but different hash', async () => {
const { router } = await newRouter()
await router.push('/#one')
expect(router.currentRoute.value.hash).toBe('#one')
await router.push('/#two')
expect(router.currentRoute.value.hash).toBe('#two')
})

describe('alias', () => {
it('does not navigate to alias if already on original record', async () => {
const { router } = await newRouter()
Expand Down Expand Up @@ -484,8 +500,6 @@ describe('Router', () => {
})
})

// it('redirects with route record redirect')

describe('Dynamic Routing', () => {
it('resolves new added routes', async () => {
const { router } = await newRouter()
Expand Down
5 changes: 4 additions & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ function extractChangingRecords(
return [leavingRecords, updatingRecords, enteringRecords]
}

// TODO: move to utils and test
function isSameRouteLocation(a: RouteLocation, b: RouteLocation): boolean {
let aLastIndex = a.matched.length - 1
let bLastIndex = b.matched.length - 1
Expand All @@ -640,6 +641,8 @@ function isSameRouteLocation(a: RouteLocation, b: RouteLocation): boolean {
aLastIndex > -1 &&
aLastIndex === bLastIndex &&
isSameRouteRecord(a.matched[aLastIndex], b.matched[bLastIndex]) &&
isSameLocationObject(a.params, b.params)
isSameLocationObject(a.params, b.params) &&
isSameLocationObject(a.query, b.query) &&
a.hash === b.hash
)
}

0 comments on commit 3862ad9

Please sign in to comment.