How to use beforeRouteEnter in setup hook?
There is no any mention of onBeforeRouteEnter hook in the documentation. There are only two hooks documented onBeforeRouteLeave and onBeforeRouteUpdate.
How to use beforeRouteEnter in setup hook?
There is no any mention of onBeforeRouteEnter hook in the documentation. There are only two hooks documented onBeforeRouteLeave and onBeforeRouteUpdate.
In the composition API, the timing of setup roughly equates to created in Vue 2. By that time, the routing has already occurred, so there would be no meaning to a beforeRouteEnter inside of setup.
You can still use beforeRouteEnter in the options API alongside setup if that works for you:
setup() {
console.log('SETUP')
},
beforeRouteEnter(to, from, next) {
// Do something
next({ path: '/foo' }); // Go somewhere else if necessary
next(); // Or stay here
}
Or beforeEnter or beforeEach in the router might serve your purposes: