Answer the question
In order to leave comments, you need to log in
How to pass dynamic parameters to next()?
i have such route in router
{
path: '/userRoom/:id',
name: 'UserRoom',
meta: { auth: true },
component: userRoom
}
router.beforeEach((to, from, next) => {
const requireAuth = to.matched.some(record => record.meta.auth)
const userData = JSON.parse(localStorage.getItem('userData'))
if (to.name === 'UserRoom' && requireAuth) {
if (userData) {
console.log('userData')
next('/userRoom/' + userData._id)
} else {
next('/registration')
}
} else {
next()
}
})
Answer the question
In order to leave comments, you need to log in
Isn't it because you go to the right address, pass the check and redirect yourself to the same address. We redirected to this address, passed the check, as a result of which we redirected to the same address again
// я перехожу на /userRoom/:id ? и прошел авторизацию?
if (to.name === 'UserRoom' && requireAuth) {
if (userData) {
console.log('userData')
// окей! Снова перехожу на /userRoom/:id
next('/userRoom/' + userData._id)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question