Accessing $route.params in VueJS

To access $route.params in VueJS, follow these steps:

  1. Define a route in your Vue router configuration that includes a dynamic segment. For example:
{
  path: '/user/:id',
  component: User,
}
  1. In your component, import the vue-router library:
import { mapGetters } from 'vuex'
  1. Use the mapGetters helper to access the $route object in your component:
computed: {
  ...mapGetters(['$route']),
},
  1. Access the params property of the $route object to retrieve the dynamic segment value:
this.$route.params.id
  1. You can now use the id value in your component as needed.

That's it! You have now accessed the $route.params in VueJS.