Skip to content

useRouteFromMiddleware Composable ​

File Information ​

  • Path: app/composables/core/common/useRouteFromMiddleware.ts
  • Purpose: Read the target route set by check-url middleware so layout/composables can use it without calling useRoute() during middleware
  • Type: Core Composable (Common)

Overview ​

Returns a serializable snapshot of the route (params, query, path, fullPath, name) stored in Nuxt useState under the key middleware-to-route. The check-url middleware sets this so that layout and composables can read the resolved brand/route without calling useRoute() during middleware execution (which can trigger Nuxt warnings or return the previous route).

Interface ​

MiddlewareRouteSnapshot: { params, query, path, fullPath, name? } — No component refs or functions, safe for SSR serialization (devalue).

Return Type ​

  • useState<MiddlewareRouteSnapshot | null> (or a ref if useState is unavailable)

Usage ​

Use in layout or composables that may run during or right after middleware:

typescript
const routeSnapshot = useRouteFromMiddleware()
const brandName = routeSnapshot.value?.params?.brand_name