Skip to content

Commit

Permalink
fix(resolve): use current location if not provided (#2390)
Browse files Browse the repository at this point in the history
Fixes #2385

<!--
Please make sure to read the Pull Request Guidelines:
https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#pull-request-guidelines
-->
  • Loading branch information
posva authored Mar 28, 2019
1 parent 53cce99 commit 7ff4de4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
40 changes: 40 additions & 0 deletions test/unit/specs/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 7ff4de4

Please sign in to comment.