Vue-router: Add documentation doc about using @click with a router-link

Created on 22 Feb 2017  路  3Comments  路  Source: vuejs/vue-router

Following #650 . Sometimes we want to use a router-link component to benefit from its visited state or other things but manually handle the @click and it's necessary to use native. Even though it's said on the vue docs, it's better to repeat ourselves a bit

ATM there's no place on the docs where we mention the @click with a router-link so I think we could add a little note at the bottom of : https://router.vuejs.org/en/api/router-link.html

2.x contribution welcome docs

Most helpful comment

I haven't checked further but it can be useful to transform it into a functional component if possible.
But I don't think it's counterintuitive to use @click.native. Quite the opposite. It's a component so I'll always use @click.native but we can make both ways work

All 3 comments

Hmm after checking the src of router-link, I think maybe it can be made a functional component to support both on and nativeOn (since it doesn't need an instance, and $router reference can be accessed from ctx.parent).
This way we can directly support @click, instead of the counterintuitive @click.native (and we can add support for .native for compatibility)

<router-link @click="foo"/>

I haven't checked further but it can be useful to transform it into a functional component if possible.
But I don't think it's counterintuitive to use @click.native. Quite the opposite. It's a component so I'll always use @click.native but we can make both ways work

Closing as we are making the router-link a functional component in #2029

Was this page helpful?
0 / 5 - 0 ratings

Related issues

achen224 picture achen224  路  3Comments

thomas-alrek picture thomas-alrek  路  3Comments

kerlor picture kerlor  路  3Comments

onlyfew picture onlyfew  路  3Comments

saman picture saman  路  3Comments