Skip to content

Commit bcc9ef5

Browse files
committed
Revert "fix: keep repeated params in query/hash relative locations"
Closes #3289 This reverts commit 4fbaa9f.
1 parent 5c4221a commit bcc9ef5

File tree

2 files changed

+39
-97
lines changed

2 files changed

+39
-97
lines changed

src/util/location.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function normalizeLocation (
2727
}
2828

2929
// relative params
30-
if (!next.path && (next.params || next.query || next.hash) && current) {
30+
if (!next.path && next.params && current) {
3131
next = extend({}, next)
3232
next._normalized = true
3333
const params: any = extend(extend({}, current.params), next.params)

test/unit/specs/location.spec.js

Lines changed: 38 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ describe('Location utils', () => {
77
expect(loc._normalized).toBe(true)
88
expect(loc.path).toBe('/abc')
99
expect(loc.hash).toBe('#hello')
10-
expect(JSON.stringify(loc.query)).toBe(
11-
JSON.stringify({
12-
foo: 'bar',
13-
baz: 'qux'
14-
})
15-
)
10+
expect(JSON.stringify(loc.query)).toBe(JSON.stringify({
11+
foo: 'bar',
12+
baz: 'qux'
13+
}))
1614
})
1715

1816
it('empty string', function () {
@@ -38,31 +36,23 @@ describe('Location utils', () => {
3836
expect(loc._normalized).toBe(true)
3937
expect(loc.path).toBe('/root/abc')
4038
expect(loc.hash).toBe('#hello')
41-
expect(JSON.stringify(loc.query)).toBe(
42-
JSON.stringify({
43-
foo: 'bar',
44-
baz: 'qux'
45-
})
46-
)
39+
expect(JSON.stringify(loc.query)).toBe(JSON.stringify({
40+
foo: 'bar',
41+
baz: 'qux'
42+
}))
4743
})
4844

4945
it('relative append', () => {
50-
const loc = normalizeLocation(
51-
'abc?foo=bar&baz=qux#hello',
52-
{
53-
path: '/root/next'
54-
},
55-
true
56-
)
46+
const loc = normalizeLocation('abc?foo=bar&baz=qux#hello', {
47+
path: '/root/next'
48+
}, true)
5749
expect(loc._normalized).toBe(true)
5850
expect(loc.path).toBe('/root/next/abc')
5951
expect(loc.hash).toBe('#hello')
60-
expect(JSON.stringify(loc.query)).toBe(
61-
JSON.stringify({
62-
foo: 'bar',
63-
baz: 'qux'
64-
})
65-
)
52+
expect(JSON.stringify(loc.query)).toBe(JSON.stringify({
53+
foo: 'bar',
54+
baz: 'qux'
55+
}))
6656
})
6757

6858
it('relative query & hash', () => {
@@ -72,92 +62,46 @@ describe('Location utils', () => {
7262
expect(loc._normalized).toBe(true)
7363
expect(loc.path).toBe('/root/next')
7464
expect(loc.hash).toBe('#hello')
75-
expect(JSON.stringify(loc.query)).toBe(
76-
JSON.stringify({
77-
foo: 'bar',
78-
baz: 'qux'
79-
})
80-
)
65+
expect(JSON.stringify(loc.query)).toBe(JSON.stringify({
66+
foo: 'bar',
67+
baz: 'qux'
68+
}))
8169
})
8270

8371
it('relative params (named)', () => {
84-
const loc = normalizeLocation(
85-
{ params: { lang: 'fr' }},
86-
{
87-
name: 'hello',
88-
params: { lang: 'en', id: 'foo' }
89-
}
90-
)
72+
const loc = normalizeLocation({ params: { lang: 'fr' }}, {
73+
name: 'hello',
74+
params: { lang: 'en', id: 'foo' }
75+
})
9176
expect(loc._normalized).toBe(true)
9277
expect(loc.name).toBe('hello')
9378
expect(loc.params).toEqual({ lang: 'fr', id: 'foo' })
9479
})
9580

9681
it('relative params (non-named)', () => {
97-
const loc = normalizeLocation(
98-
{ params: { lang: 'fr' }},
99-
{
100-
path: '/en/foo',
101-
params: { lang: 'en', id: 'foo' },
102-
matched: [{ path: '/:lang(en|fr)/:id' }]
103-
}
104-
)
82+
const loc = normalizeLocation({ params: { lang: 'fr' }}, {
83+
path: '/en/foo',
84+
params: { lang: 'en', id: 'foo' },
85+
matched: [{ path: '/:lang(en|fr)/:id' }]
86+
})
10587
expect(loc._normalized).toBe(true)
10688
expect(loc.path).toBe('/fr/foo')
10789
})
10890

109-
it('relative query named', () => {
110-
const loc = normalizeLocation(
111-
{ query: { lang: 'fr' }},
112-
{
113-
name: 'hello',
114-
hash: '#foo',
115-
params: { id: 'foo' }
116-
}
117-
)
118-
expect(loc._normalized).toBe(true)
119-
expect(loc.name).toBe('hello')
120-
expect(loc.params).toEqual({ id: 'foo' })
121-
expect(loc.query).toEqual({ lang: 'fr' })
122-
expect(loc.hash).toBe(undefined)
123-
})
124-
125-
it('relative hash named', () => {
126-
const loc = normalizeLocation(
127-
{ hash: '#foo' },
128-
{
129-
name: 'hello',
130-
query: { lang: 'fr' },
131-
params: { id: 'foo' }
132-
}
133-
)
134-
expect(loc._normalized).toBe(true)
135-
expect(loc.name).toBe('hello')
136-
expect(loc.params).toEqual({ id: 'foo' })
137-
expect(loc.query).toBe(undefined)
138-
expect(loc.hash).toBe('#foo')
139-
})
140-
14191
it('custom regex can be case insensitive', () => {
142-
const loc = normalizeLocation(
143-
{ params: { lang: 'FR' }},
144-
{
145-
path: '/en/foo',
146-
params: { lang: 'en', id: 'foo' },
147-
matched: [{ path: '/:lang(en|fr)/:id' }]
148-
}
149-
)
92+
const loc = normalizeLocation({ params: { lang: 'FR' }}, {
93+
path: '/en/foo',
94+
params: { lang: 'en', id: 'foo' },
95+
matched: [{ path: '/:lang(en|fr)/:id' }]
96+
})
15097
expect(loc._normalized).toBe(true)
15198
expect(loc.path).toBe('/FR/foo')
15299
})
153100

154101
it('relative append', () => {
155102
const loc = normalizeLocation({ path: 'a' }, { path: '/b' }, true)
156103
expect(loc.path).toBe('/b/a')
157-
const loc2 = normalizeLocation(
158-
{ path: 'a', append: true },
159-
{ path: '/b' }
160-
)
104+
const loc2 = normalizeLocation({ path: 'a', append: true }, { path: '/b' })
161105
expect(loc2.path).toBe('/b/a')
162106
})
163107

@@ -170,12 +114,10 @@ describe('Location utils', () => {
170114
expect(loc._normalized).toBe(true)
171115
expect(loc.path).toBe('/abc')
172116
expect(loc.hash).toBe('#lol')
173-
expect(JSON.stringify(loc.query)).toBe(
174-
JSON.stringify({
175-
foo: 'bar',
176-
baz: 'qux'
177-
})
178-
)
117+
expect(JSON.stringify(loc.query)).toBe(JSON.stringify({
118+
foo: 'bar',
119+
baz: 'qux'
120+
}))
179121
})
180122

181123
it('skip normalized', () => {

0 commit comments

Comments
 (0)