New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setting nuxt route middleware in routeRules
#21913
Comments
I like the idea but only as also discussed in a team meeting, using
|
I like nuxtMiddleware. It gives a good mental model, we already have nuxtPlugin and nitroPlugin, we could go all the way and rename with nuxtMiddleware and nitroMiddleware. |
Would this cover server middleware also? Main use case is I want to by default protect all API routes so they are authenticated, but have some kind of allow list of which ones can be public. I suppose I could do this with regex and checking the path in the middleware currently, definitely would prefer setting in the nuxt config though. |
yes this would be such a nice feature , im suprised it is currently not possible as a config |
Nuxt currently supports defining global route middleware (with
.global.
suffix) and named route middleware that can be opted-into per-route usingdefinePageMeta
.But in some cases there are more complex patterns, where users may want to set middleware for a group of pages or apply a named middleware to the entire site. For example:
nuxt.config.ts
#19948To resolve these issues, we can support a new route rule. Something like:
We're currently thinking about the best name for the rule. I think at the moment
routeMiddleware
makes most sense as we havedefineNuxtRouteMiddleware
but ideas welcome to make it clear that this is only relevant in the Vue part of your app (i.e. not applied to nitro routes).Note: This rule will be possible once #21370 is implemented.
The text was updated successfully, but these errors were encountered: