fix(nuxt): don't warn about calling useRoute in SFC setup (#30788)

This commit is contained in:
Peter Radko 2025-01-29 01:15:57 +03:00 committed by GitHub
parent b7998f8edb
commit c01050f7ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,7 +18,7 @@ export const useRouter: typeof _useRouter = () => {
/** @since 3.0.0 */
export const useRoute: typeof _useRoute = () => {
if (import.meta.dev && isProcessingMiddleware()) {
if (import.meta.dev && !getCurrentInstance() && 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 (hasInjectionContext()) {