Vuejs Route Redirect On Refresh
When i use refresh button in my browser or hit f5 on keyboard instead of refreshing my page it redirects to home page. Code router.js import Vue from 'vue'; import VueRouter from '
Solution 1:
Solved
working code
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
// this route requires auth, check if logged in// if not, redirect to login page.if (!store.getters.isLoggedIn) {
next({
name: 'login'
})
} else {
next()
}
}
if (to.matched.some(record => record.meta.requiresAdmin)) {
// this route requires auth, check if logged in// if not, redirect to home page.if (!store.getters.loggedUser.type == 'admin') {
next({
name: 'home'
})
} else {
next()
}
}
else {
next() // make sure to always call next()!
}
})
Hope it help others.
Post a Comment for "Vuejs Route Redirect On Refresh"