0👍
✅
Try beforeRouteEnter
navigation guard.
Navigation guards.
called before the route that renders this component is confirmed.
import store from "./store";
export default {
...
beforeRouteEnter(to, from ,next) {
if (store.state.permissions.map(p => p.name).indexOf("view-clients") === -1) {
next({ "name": "dashboard" });
}
}
...
}
The
beforeRouteEnter
guard does NOT have access tothis
, because the
guard is called before the navigation is confirmed, thus the new
entering component has not even been created yet.
So to access store
you have to import it manually.
Source:stackexchange.com