From: Eduardo San Martin Morote Date: Wed, 8 Apr 2020 10:03:08 +0000 (+0200) Subject: fix(link): not active when matched is empty X-Git-Tag: v4.0.0-alpha.5~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acd644db70793da7719b321b2dcdd537ec358f9c;p=thirdparty%2Fvuejs%2Frouter.git fix(link): not active when matched is empty --- diff --git a/__tests__/RouterLink.spec.ts b/__tests__/RouterLink.spec.ts index 0ab1087e..e92b78b2 100644 --- a/__tests__/RouterLink.spec.ts +++ b/__tests__/RouterLink.spec.ts @@ -227,6 +227,20 @@ const locations: Record< name: undefined, }, }, + notFound: { + string: '/not-found', + normalized: { + fullPath: '/not-found', + path: '/not-found', + params: {}, + meta: {}, + query: {}, + hash: '', + matched: [], + redirectedFrom: undefined, + name: undefined, + }, + }, } describe('RouterLink', () => { @@ -333,6 +347,15 @@ describe('RouterLink', () => { expect(el.querySelector('a')!.className).toContain('nav-item') }) + it('is not active on a non matched location', () => { + const { el } = factory( + locations.notFound.normalized, + { to: locations.basic.string }, + locations.basic.normalized + ) + expect(el.querySelector('a')!.className).toBe('') + }) + it('is not active with more repeated params', () => { const { el } = factory( locations.repeatedParams2.normalized, diff --git a/src/components/Link.ts b/src/components/Link.ts index 495f3e5a..efe53121 100644 --- a/src/components/Link.ts +++ b/src/components/Link.ts @@ -46,6 +46,7 @@ export function useLink(props: UseLinkOptions) { ) const isExactActive = computed( () => + activeRecordIndex.value > -1 && activeRecordIndex.value === currentRoute.value.matched.length - 1 && isSameLocationObject(currentRoute.value.params, route.value.params) )