Menu Close

How to get route URL parameters in a page with Nuxt.js?

Sometimes, we want to get route URL parameters in a page with Nuxt.js.

In this article, we’ll look at how to get route URL parameters in a page with Nuxt.js.

How to get route URL parameters in a page with Nuxt.js?

To get route URL parameters in a page with Nuxt.js, we can get them from the this.$route.params object.

For instance, we write

<script>
//...
export default {
  //...
  mounted() {
    console.log(this.$route.params.slug);
  },
  //...
};
</script>

to get the value of the slug URL parameter with this.$route.params.slug).

Conclusion

To get route URL parameters in a page with Nuxt.js, we can get them from the this.$route.params object.

Posted in vue