Search code examples
vue.jsvuejs3vue-routervue-composition-apivue-router4

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


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.


Solution

  • 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 
               
            },
        };