Sometimes, we want to get previous page URL with Vue Router.
In this article, we’ll look at how to get previous page URL with Vue Router.
How to get previous page URL with Vue Router?
To get previous page URL with Vue Router, we can get it from the from
parameter of the beforeRouterEnter
hook.
For instance, we write
<script>
export default {
//...
beforeRouteEnter(to, from, next) {
console.log(from);
},
//...
};
</script>
to add the beforeRouteEnter
hook into our component and get the previous page URL from the from
parameter.
Conclusion
To get previous page URL with Vue Router, we can get it from the from
parameter of the beforeRouterEnter
hook.