Skip to content

Commit 7ff4de4

Browse files
authoredMar 28, 2019
fix(resolve): use current location if not provided (#2390)
Fixes #2385 <!-- Please make sure to read the Pull Request Guidelines: https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#pull-request-guidelines -->
1 parent 53cce99 commit 7ff4de4

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
 

‎src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ export default class VueRouter {
186186
normalizedTo: Location,
187187
resolved: Route
188188
} {
189+
current = current || this.history.current
189190
const location = normalizeLocation(
190191
to,
191-
current || this.history.current,
192+
current,
192193
append,
193194
this
194195
)

‎test/unit/specs/api.spec.js

+40
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,46 @@ describe('router.onReady', () => {
4444
})
4545
})
4646

47+
describe('route matching', () => {
48+
it('resolves parent params when using current route', () => {
49+
const router = new Router({
50+
mode: 'abstract',
51+
routes: [
52+
{
53+
path: '/a/:id',
54+
component: { name: 'A' },
55+
children: [{ name: 'b', path: 'b', component: { name: 'B' }}]
56+
}
57+
]
58+
})
59+
60+
router.push('/a/1')
61+
62+
const { route, resolved } = router.resolve({ name: 'b' })
63+
expect(route.params).toEqual({ id: '1' })
64+
expect(resolved.params).toEqual({ id: '1' })
65+
})
66+
67+
it('can override currentRoute', () => {
68+
const router = new Router({
69+
mode: 'abstract',
70+
routes: [
71+
{
72+
path: '/a/:id',
73+
component: { name: 'A' },
74+
children: [{ name: 'b', path: 'b', component: { name: 'B' }}]
75+
}
76+
]
77+
})
78+
79+
router.push('/a/1')
80+
81+
const { route, resolved } = router.resolve({ name: 'b' }, { params: { id: '2' }, path: '/a/2' })
82+
expect(route.params).toEqual({ id: '2' })
83+
expect(resolved.params).toEqual({ id: '2' })
84+
})
85+
})
86+
4787
describe('router.addRoutes', () => {
4888
it('should work', () => {
4989
const router = new Router({

0 commit comments

Comments
 (0)