feat(nuxt): warn in dev when useRoute is used in middleware (#20050)

This commit is contained in:
Daniel Roe 2023-04-03 11:36:17 +01:00 committed by GitHub
parent 79ad5ac9bc
commit 61699f864e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,9 @@ export const useRouter = () => {
}
export const useRoute = (): RouteLocationNormalizedLoaded => {
if (process.dev && isProcessingMiddleware()) {
console.warn('[nuxt] Calling `useRoute` within middleware may lead to misleading results. Instead, use the (to, from) arguments passed to the middleware to access the new and old routes.')
}
if (getCurrentInstance()) {
return inject('_route', useNuxtApp()._route)
}