Skip to content

Commit

Permalink
fix(normalizeLocation): create a copy with named locations
Browse files Browse the repository at this point in the history
Fix #2121
  • Loading branch information
posva committed Jul 7, 2018
1 parent 3cad567 commit d5129a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/util/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export function normalizeLocation (
): Location {
let next: Location = typeof raw === 'string' ? { path: raw } : raw
// named target
if (next.name || next._normalized) {
if (next._normalized) {
return next
} else if (next.name) {
return extend({}, raw)
}

// relative params
Expand Down
9 changes: 9 additions & 0 deletions test/unit/specs/location.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,14 @@ describe('Location utils', () => {
const loc2 = normalizeLocation(loc1)
expect(loc1).toBe(loc2)
})

it('creates copies when not normalized', () => {
const l1 = { name: 'foo' }
expect(normalizeLocation(l1)).not.toBe(l1)
const l2 = { path: '/foo' }
expect(normalizeLocation(l2)).not.toBe(l2)
const l3 = { path: '/foo', query: { foo: 'foo' } }
expect(normalizeLocation(l3)).not.toBe(l3)
})
})
})

0 comments on commit d5129a3

Please sign in to comment.