[Vuejs]-Data in App component in beforeMount is not available

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 to this, 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.

Leave a comment