From 7ff4de4879dbe396827c9ab30dfc427288056eb8 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 28 Mar 2019 18:20:13 +0100 Subject: [PATCH] fix(resolve): use current location if not provided (#2390) Fixes #2385 --- src/index.js | 3 ++- test/unit/specs/api.spec.js | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) 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({