Categories
Vue Answers

How to get previous page URL with Vue Router?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *