From: Eduardo San Martin Morote Date: Tue, 7 Apr 2020 10:19:46 +0000 (+0200) Subject: feat(link): allow `custom` prop X-Git-Tag: v4.0.0-alpha.5~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=874510be69c3b068970e8a90ae251cf487d6acf9;p=thirdparty%2Fvuejs%2Frouter.git feat(link): allow `custom` prop --- diff --git a/__tests__/RouterLink.spec.ts b/__tests__/RouterLink.spec.ts index 558a6f07..0ab1087e 100644 --- a/__tests__/RouterLink.spec.ts +++ b/__tests__/RouterLink.spec.ts @@ -576,5 +576,26 @@ describe('RouterLink', () => { expect(el.innerHTML).toMatchSnapshot() }) + + it('renders an anchor by default', () => { + const { el } = factory( + locations.basic.normalized, + { to: locations.basic.string }, + locations.basic.normalized + ) + + expect(el.children[0].tagName).toBe('A') + expect(el.children).toHaveLength(1) + }) + + it('can customize the rendering and remove the wrapping `a`', () => { + const { el } = factory( + locations.basic.normalized, + { to: locations.basic.string, custom: true }, + locations.basic.normalized + ) + + expect(el.innerHTML).not.toContain('') + }) }) }) diff --git a/src/components/Link.ts b/src/components/Link.ts index 30e9649e..a487bc47 100644 --- a/src/components/Link.ts +++ b/src/components/Link.ts @@ -80,6 +80,7 @@ export const Link = defineComponent({ type: String, default: 'router-link-exact-active', }, + custom: Boolean, }, setup(props, { slots, attrs }) { @@ -91,17 +92,20 @@ export const Link = defineComponent({ })) return () => { - return h( - 'a', - { - 'aria-current': link.isExactActive ? 'page' : null, - onClick: link.navigate, - href: link.href, - ...attrs, - class: elClass.value, - }, - slots.default && slots.default(link) - ) + const children = slots.default && slots.default(link) + return props.custom + ? children + : h( + 'a', + { + 'aria-current': link.isExactActive ? 'page' : null, + onClick: link.navigate, + href: link.href, + ...attrs, + class: elClass.value, + }, + children + ) } }, })