Vue-router replace not working?

0

I'm developing a PWA and I'm having problems with the router, because when I use the back button on my smartphone it goes through all the routes I've visited previously and only after leaving the application, and I want it when the user uses the go back the first time, at most in the second click it close the application.

I have already configured some things in the beforeEach of the 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 have already checked all the places where you use the router and in all of them I configured to use replace() instead of push()

    
asked by anonymous 19.04.2018 / 14:37

1 answer

0

Your beforeEach is not correct. It should be in the same scope as your router is instantiated.

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

router.beforeEach((to, from, next) => {
  // ...
})
    
21.04.2018 / 13:44