How to access $route property inside setup method (Vue 3)?

Viewed 1670

How can I access $route.params property inside setup method in Vue.js? When I try to access it inside other method, or inside template everything works fine, but i cannot access it inside setup method.

1 Answers

You should use composable function useRoute to get the current route:

import { useRoute } from "vue-router";
    export default {
        setup() {
          const route =useRoute()
          //then use route.params 
           
        },
    };
Related