Skip to content

Instantly share code, notes, and snippets.

@moreta
Last active May 16, 2019 03:42
Show Gist options
  • Save moreta/c6ebd750589a60f4b53719a0445c42a6 to your computer and use it in GitHub Desktop.
Save moreta/c6ebd750589a60f4b53719a0445c42a6 to your computer and use it in GitHub Desktop.
Workaround vue router-link current path click no action (router-linkのcurrent pathの無反応回避策)
@moreta
Copy link
Author

moreta commented May 15, 2019

current pathと同じの場合ページがreloadされてもいい時には <router-link>の代わりにこれを使う

@moreta
Copy link
Author

moreta commented May 15, 2019

@moreta
Copy link
Author

moreta commented May 16, 2019

page reloadでscroll positionを維持したいなら

window.location.href = to
の代わりに
this.$router.go()を使う

また browserのpage reloadをしたくない場合には
window.location.href = to
の代わりに
このように、新しいquery stringをつけてreplaceする

const query = { ...this.$route.query, _: new Date().getTime() };
const newRoute = { ...this.$route, query };
this.$router.replace(newRoute);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment