[Solved] Intercept/Listen on Back Button Click of Browser/Phone
-
Good day. Is there any way to intercept/listen on the back button of the browser/phone? I would like to determine the route the user will be directed when the back button is clicked/pressed. For example in my situation, when the user clicks the back button simultaneously for a couple of times, the user is directed to the login page which is the app’s previous window(s). I would like to retain the functionality that the user can go back to the previous page but prevent it from visiting the login page when the user is already logged in.
-
did you check the docs? https://quasar-framework.org/components/handling-back-button.html.
what i can think is to use router guard and vuex store for maintaining the back button clicks. -
@metalsadman Yup I did. But it doesn’t fit with my use case since it can’t determine what is the next route when the user clicked the back button. Router guards only handle the beforeEach and afterEach, but it can’t handle when the user clicked the back button based on my tests.
-
It seems that I am implementing the router guards the wrong way. After correcting the code, the router guards now detects changes in URL even if the uses the back button.
-
i put a Router.beforeEach in the router/index.js, to perform checks/validations etc…