expect(router.push).toHaveBeenCalledTimes(1)
})
+ it('allows adding more click listeners', async () => {
+ const onClick = jest.fn()
+ const { router, wrapper } = await factory(
+ START_LOCATION_NORMALIZED,
+ { to: locations.basic.string, onClick },
+ locations.basic.normalized
+ )
+ wrapper.find('a')!.trigger('click')
+ expect(router.push).toHaveBeenCalledTimes(1)
+ expect(onClick).toHaveBeenCalledTimes(1)
+ })
+
+ it('allows adding custom classes', async () => {
+ const { wrapper } = await factory(
+ locations.basic.normalized,
+ { to: locations.basic.string, class: 'custom class' },
+ locations.basic.normalized
+ )
+ expect(wrapper.find('a')!.classes()).toEqual([
+ 'router-link-active',
+ 'router-link-exact-active',
+ 'custom',
+ 'class',
+ ])
+ })
+
it('calls router.replace when clicked with replace prop', async () => {
const { router, wrapper } = await factory(
START_LOCATION_NORMALIZED,
import { isSameRouteLocationParams, isSameRouteRecord } from './location'
import { routerKey, routeLocationKey } from './injectionSymbols'
import { RouteRecord } from './matcher/types'
-import { assign } from './utils'
import { NavigationFailure } from './errors'
export interface RouterLinkOptions {
},
},
- setup(props, { slots, attrs }) {
+ setup(props, { slots }) {
const link = reactive(useLink(props))
const { options } = inject(routerKey)!
? children
: h(
'a',
- assign(
- {
- 'aria-current': link.isExactActive
- ? props.ariaCurrentValue
- : null,
- onClick: link.navigate,
- href: link.href,
- },
- attrs,
- {
- class: elClass.value,
- }
- ),
+ {
+ 'aria-current': link.isExactActive
+ ? props.ariaCurrentValue
+ : null,
+ href: link.href,
+ // this would override user added attrs but Vue will still add
+ // the listener so we end up triggering both
+ onClick: link.navigate,
+ class: elClass.value,
+ },
children
)
}