When I'm outside of Vue component, i.e. in a store, router.currentRoute.name is undefined:
import router from '@/router'
console.log(router.currentRoute.name) // returns "undefined"
I can't use useRouter composable either, because it doesn't work outside of components:
import { useRouter } from 'vue-router'
const router = useRouter()
console.log(router) // returns "undefined"
This has never been a problem in Vue 2, where router was created with new Router().
In Vue 3, when using router with the new createRouter(), the exported router doesn't seem to expose router.currentRoute.
In Vue 3 instead of
route name should be accessed with: