vue-router: Is there any way to force navigation when clicking on a router-link even if the route doesn't change?
What problem does this feature solve?
Reload current page’s state or refresh the page.
For example, I have a <HeaderBar> which contains a Home button, just like the Facebook one.
If I’m in another page (rather than Home), when I hit this button, it will navigate to Home. But when I’m in Home page, hit this button it does nothing.
It’s expected to reload the page, and scroll to the top, right?
Please don’t tell me to write out an action to refresh the state and scroll to top. This header bar is a shared component, and the Home button can be hit at any where.
What does the proposed API look like?
Some thing like
<router-link :to="{ name: 'Home', force: true }">Home</router-link>
or
this.$router.replace({ name: 'Home', force: true });
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 19 (2 by maintainers)
You can reload the page, but you should handle the refresh in a click handler if you want to have that custom behaviour
Duplicate of https://github.com/vuejs/vue-router/issues/974
Same problem. Resolved : click link profile event:
@leoyli
Yeah, I’ve tried to bind a key to
router-viewbefore, but it didn’t work.Since the
fullPathhave no changes, how does it suppose to reload the page?Can you give me an example, plz. Talk is cheap, you know.
yeah, they are not supposed to be triggered as you are in the same route with no param change or whatsoever… You need to refactor the code in methods and call them in both places. Cheers
I’ve just ran into this problem also.
Use case:
/profile/:userIdto a component called “Profile”Try:
npm i vue-state-routerinstead ofvue-router. Totally same API. Gives you these feature:This is my trick to get through this situation:
<base-link>just likes the<router-link>and use this one instead of<router-link>.:toroute is different from the current route, render<router-link>in the template.<a>tag with:href=this.$router.resolve(this.to).route.fullPathand add an click event handler to redirect to another page named ‘Refresh’;Everything works just fine so far.