Vue-router replace not working?

Asked

Viewed 226 times

0

I am developing a PWA and I am having problems with the router, because when I use the back button of my smartphone it goes through all the previously visited routes only to after exit the application, and I want when the user uses the back button the first time, at most in the second click it closes the application.

I’ve already set up a few things on beforeEach router:

export default (to, from, next) => {
  if (//verifica se o usuario está logado, caso não, encaminha para o login) {
    next('/login')
  }
  else {
    next({replace: true})
  }
}

And every time I call the router to redirect to some different page or route instead of using router.push(rota) I’m using router.replace(rota)

I’ve checked all the places where you use the router and in all of them I’ve set up to use the replace() instead of push()

1 answer

0


Your beforeEach is not correct. It must be in the same scope where its instantiated router.

const router = new VueRouter({ ... })

router.beforeEach((to, from, next) => {
  // ...
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.