How to protect routes using store
-
I am trying to protect routes based on store, but I can’t access store from routes. What is best practice to handle this?
I see preFetch example use directly in components, should I follow this or I can do check in routes file?
I create a sort of middleware that check meta in routes. But unfortunately I can’t access store from routes.
Thanks -
@twa
you can pass around your store context in your router/index.js export default function or other means like exposing it from a boot file or tye store/index.js file, then import it where you need it. Make a search there should be topics about it in here, or refer back in the docs for some examples, ie. Boot, router or vuex sections.You are correct with using a middleware/vue router navigation guard.
Edit: answered you on a relevant thread that you commented on.