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('</a>')
+ })
})
})
type: String,
default: 'router-link-exact-active',
},
+ custom: Boolean,
},
setup(props, { slots, attrs }) {
}))
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
+ )
}
},
})