0

I need to detect the back function in the browser and need to redirect to a different page using vue js. My attempt is as below.

mounted: function () { window.onpopstate = function(event) { this.$router.push({ path: "/register" }); }; } 

But it will not identify $router and saying it's not a function. How can I solve this problem?

1

1 Answer 1

1

this inside the function is not instance of vue component so it will not work. Try this code:

 mounted: function () { window.onpopstate = (event) => { this.$router.push({ path: "/register" }); }; 
Sign up to request clarification or add additional context in comments.

Comments