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
Extend Nuxt 3 Middleware usage. #21454
Comments
@danielroe What's your opinion on this? |
I believe you can already do this with a global middleware, let's name it export default defineNuxtRouteMiddleware((to) => {
// Check if next route has master layout
if (to.meta.layout !== 'master') return
// Do the check if user is authenticated
}) |
The tricky thing with this is that Another option might be something like this: export default defineNuxtRouteMiddleware((to) => {
//
}, { filter: page => page.meta.layout === 'master' }) But I'm not sure that saves much space compared to @Atinux's suggestion, which seems good to me. |
@Atinux It works, Thanks |
I haven't dedicated much consideration to this idea yet, as we can customize the default layout for all pages using the
|
Describe the feature
I was wondering if we could add the layout name as a prefix to the middleware name, similar to how we add global middleware for all pages.
For example:
If we have two layouts,
master.vue
anddefault.vue
, and we only want to run theauth.js
middleware for pages that are using the master layout, we can name the fileauth.master.js
. Now the auth middleware should only run for pages that are using the master layout. Nuxt should be smart enough to detect if the prefix is global, and if so, run that middleware for every page. If the prefix is not global, Nuxt should check if there is any layout that matches the middleware prefix, and if yes, run that middleware for every page that uses that layout.Alternatively,
Nuxt could provide some sort of composable/compiler macro that allows us to add middleware to a layout such as:
Additional information
Final checks
The text was updated successfully, but these errors were encountered: