0👍
If you need to run this function before every route in your application, you could use router’s beforeEach
function to check that.
router.beforeEach((to, from, next) => { }
.
If this is only for one or some routes, you could set the property beforeEnter to the route.
https://router.vuejs.org/guide/advanced/navigation-guards.html#per-route-guard
In your beforeEach function, you need to make the validation you said you want.
if(this.$store.getters.user.id !== to.params.id)
next({
name: 'home',
params: { id: this.$store.getters.user.id }
});
Source:stackexchange.com