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.
Asked
Active
Viewed 3,328 times
1 Answers
16
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
},
};

Boussadjra Brahim
- 82,684
- 19
- 144
- 164
-
1This worked for me - `const route = useRouter();let id = route.currentRoute.value.query.id;` – Mahmudul Hasan Jun 16 '23 at 06:23