vuejs / router

🚦 The official router for Vue.js
https://router.vuejs.org/
MIT License
3.77k stars 1.16k forks source link

with vue3.4 + router4 or above useRoute() or useRouter() will return undefined #2123

Closed jesseice closed 6 months ago

jesseice commented 6 months ago

Reproduction

empty

Steps to reproduce the bug

const route = useRoute(); route // undefined

Expected behavior

return the current routing information

Actual behavior

return undefined

Additional information

No response

posva commented 6 months ago

useRoute() must be used within script setup. It's only undefined when called in the wrong places. BTW, use discussions or the discord chat to ask questions, thanks!