Clear 'vue-router' history when loading main menu

In a PWA I am using VueJS and I am having problems with the back button of the smartphone, because when I use it the PWA does what is most logical and returns to the previous screen.

But I just enter the PWA and log in and when I use the back button it goes back to the login screen, and not only 1 time, but at least 3 times until actually close the PWA.

Currently navigation is done using router.push('/nomeDaRota')

My question is: how do I make that when I log in and enter the main menu the history of vue-router clean and exit the application without going back several times on the screen??

Author: LeonardoEbert, 2018-04-12

1 answers

Unfortunately (or fortunately) it is not possible to change the browsing history, for security reasons, browsers do not allow it.

If you want to find a contour solution, you can try something during beforeRouteEnter

beforeRouteEnter(to, from, next) {
  next(vm => {
    // tente algo aqui usando o 'to' e o 'from'
  });
}
 1
Author: Tobias Mesquita, 2018-04-12 21:01:11