Skip to content

Commit d5129a3

Browse files
committed
fix(normalizeLocation): create a copy with named locations
Fix #2121
1 parent 3cad567 commit d5129a3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: src/util/location.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ export function normalizeLocation (
1515
): Location {
1616
let next: Location = typeof raw === 'string' ? { path: raw } : raw
1717
// named target
18-
if (next.name || next._normalized) {
18+
if (next._normalized) {
1919
return next
20+
} else if (next.name) {
21+
return extend({}, raw)
2022
}
2123

2224
// relative params

Diff for: test/unit/specs/location.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,14 @@ describe('Location utils', () => {
120120
const loc2 = normalizeLocation(loc1)
121121
expect(loc1).toBe(loc2)
122122
})
123+
124+
it('creates copies when not normalized', () => {
125+
const l1 = { name: 'foo' }
126+
expect(normalizeLocation(l1)).not.toBe(l1)
127+
const l2 = { path: '/foo' }
128+
expect(normalizeLocation(l2)).not.toBe(l2)
129+
const l3 = { path: '/foo', query: { foo: 'foo' } }
130+
expect(normalizeLocation(l3)).not.toBe(l3)
131+
})
123132
})
124133
})

0 commit comments

Comments
 (0)