diff --git a/src/index.js b/src/index.js index a1a7b8507..69c3cc0c8 100644 --- a/src/index.js +++ b/src/index.js @@ -186,9 +186,10 @@ export default class VueRouter { normalizedTo: Location, resolved: Route } { + current = current || this.history.current const location = normalizeLocation( to, - current || this.history.current, + current, append, this ) diff --git a/test/unit/specs/api.spec.js b/test/unit/specs/api.spec.js index 57e912cd9..5fce2e885 100644 --- a/test/unit/specs/api.spec.js +++ b/test/unit/specs/api.spec.js @@ -44,6 +44,46 @@ describe('router.onReady', () => { }) }) +describe('route matching', () => { + it('resolves parent params when using current route', () => { + const router = new Router({ + mode: 'abstract', + routes: [ + { + path: '/a/:id', + component: { name: 'A' }, + children: [{ name: 'b', path: 'b', component: { name: 'B' }}] + } + ] + }) + + router.push('/a/1') + + const { route, resolved } = router.resolve({ name: 'b' }) + expect(route.params).toEqual({ id: '1' }) + expect(resolved.params).toEqual({ id: '1' }) + }) + + it('can override currentRoute', () => { + const router = new Router({ + mode: 'abstract', + routes: [ + { + path: '/a/:id', + component: { name: 'A' }, + children: [{ name: 'b', path: 'b', component: { name: 'B' }}] + } + ] + }) + + router.push('/a/1') + + const { route, resolved } = router.resolve({ name: 'b' }, { params: { id: '2' }, path: '/a/2' }) + expect(route.params).toEqual({ id: '2' }) + expect(resolved.params).toEqual({ id: '2' }) + }) +}) + describe('router.addRoutes', () => { it('should work', () => { const router = new Router({