From: Eduardo San Martin Morote Date: Tue, 21 Apr 2020 11:46:19 +0000 (+0200) Subject: fix(link): preserve the alias path X-Git-Tag: v4.0.0-alpha.8~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fffa58585ac89e9fb6b648e61e499a9ee3a9e217;p=thirdparty%2Fvuejs%2Frouter.git fix(link): preserve the alias path --- diff --git a/__tests__/RouterLink.spec.ts b/__tests__/RouterLink.spec.ts index 4cc0168c..34cf3adc 100644 --- a/__tests__/RouterLink.spec.ts +++ b/__tests__/RouterLink.spec.ts @@ -54,7 +54,7 @@ const locations: Record< hash: '', matched: [records.home], redirectedFrom: undefined, - name: undefined, + name: 'home', }, }, foo: { @@ -131,7 +131,7 @@ const locations: Record< hash: '', matched: [records.homeAlias], redirectedFrom: undefined, - name: undefined, + name: 'home', }, }, @@ -564,7 +564,24 @@ describe('RouterLink', () => { wrapper.find('a')!.click() await nextTick() expect(router.push).toHaveBeenCalledTimes(1) - expect(router.push).toHaveBeenCalledWith(locations.basic.normalized) + }) + + it('calls router.push with the correct location for aliases', async () => { + const { router, wrapper } = await factory( + START_LOCATION_NORMALIZED, + { to: locations.alias.string }, + locations.alias.normalized + ) + wrapper.find('a')!.click() + await nextTick() + expect(router.push).toHaveBeenCalledTimes(1) + expect(router.push).not.toHaveBeenCalledWith( + expect.objectContaining({ + // this is the original name but if we push with this location, we will + // not have the alias on the url + name: 'home', + }) + ) }) describe('v-slot', () => { diff --git a/__tests__/__snapshots__/RouterLink.spec.ts.snap b/__tests__/__snapshots__/RouterLink.spec.ts.snap index 933038ad..360a57a3 100644 --- a/__tests__/__snapshots__/RouterLink.spec.ts.snap +++ b/__tests__/__snapshots__/RouterLink.spec.ts.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`RouterLink v-slot provides information on v-slot 1`] = `" route: {\\"href\\":\\"/home\\",\\"fullPath\\":\\"/home\\",\\"path\\":\\"/home\\",\\"params\\":{},\\"meta\\":{},\\"query\\":{},\\"hash\\":\\"\\",\\"matched\\":[{}]} href: \\"/home\\" isActive: \\"true\\" isExactActive: \\"true\\" "`; +exports[`RouterLink v-slot provides information on v-slot 1`] = `" route: {\\"href\\":\\"/home\\",\\"fullPath\\":\\"/home\\",\\"path\\":\\"/home\\",\\"params\\":{},\\"meta\\":{},\\"query\\":{},\\"hash\\":\\"\\",\\"matched\\":[{}],\\"name\\":\\"home\\"} href: \\"/home\\" isActive: \\"true\\" isExactActive: \\"true\\" "`; diff --git a/src/components/Link.ts b/src/components/Link.ts index 9428b7e4..d6295f34 100644 --- a/src/components/Link.ts +++ b/src/components/Link.ts @@ -56,7 +56,7 @@ export function useLink(props: UseLinkOptions) { function navigate(e: MouseEvent = {} as MouseEvent) { // TODO: handle navigate with empty parameters for scoped slot and composition api - if (guardEvent(e)) router.push(route.value) + if (guardEvent(e)) router.push(unref(props.to)) } return {