2

In Vue2, I can use this.$route.path

In Vue3, I can use useRouter()

but in Vue2.7 composition api, both of them I can't use.

1 Answers1

4

For folks coming here from google:

Vue Router 3(current latest version is 3.6.5) provides composables for you to use, check out release notes: https://github.com/vuejs/vue-router/blob/dev/CHANGELOG.md#360-2022-08-22

You would import it like so: import { useRouter, useRoute } from 'vue-router/composables';

And for the rest usage/docs you can refer to Vue Router 4 composable docs: https://router.vuejs.org/guide/advanced/composition-api.html

Russ Deneychuk
  • 676
  • 3
  • 14
  • 2
    this worked for me, thnx – 4givN Jun 09 '23 at 14:23
  • 1
    Had this been on the documentation, it would've saved me 10 hours of debugging with my incomplete implementation of `useRoute()` which is simply `getCurrentInstance().proxy.$route` – kshksdrt Aug 14 '23 at 07:17