Route Middleware does not get triggered if its defined inside layout
See original GitHub issueEnvironment
- Package Manager:
npm@8.9.0
- Builder:
vite
- User Config:
modules
,ssr
,vite
,plugins
,css
- Runtime Modules:
@nuxtjs/tailwindcss@5.1.2
,@pinia/nuxt@0.1.9
- Build Modules:
-
Reproduction
StackBlitz URL: https://stackblitz.com/edit/github-ghahvp?file=middleware/testmid.ts
Describe the bug
middlewares are working for pages, but not for layouts see stackblitz.
definePageMeta({
middleware: ["somelayout"]
})
If you use this code inside an page, it works. But if you use it inside an layout, and an page uses that layout it does not get triggered. This functionality actually works in Nuxt2
Additional context
My intention was:
I have 2 layouts: - Default (no auth) - Dashboard (with auth)
In nuxt 2 i was able to put my middleware inside of the dashboard layout. Whenever i made a new page for the dashboard, i just added layout: "dashboard"
and the dashboard CSS with the authentication middleware got applied.
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Global Middleware not being triggered
When I try to access an URL that doesn't exists inside routes.ts it gives a standard 404 error, but I want to get...
Read more >Middleware - Laravel - The PHP Framework For Web ...
For example, Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware...
Read more >Using middleware
Route handlers enable you to define multiple routes for a path. The example below defines two routes for GET requests to the /user/:id...
Read more >Complete Guide to Express Middleware
Express executes middleware in the order they are added, so if we make ... Next we have defined a route with url product...
Read more >Middleware | NestJS - A progressive Node.js framework
Middleware is a function which is called before the route handler. ... middleware function in the stack. if the current middleware function does...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lobo-tuerto You can define the middleware in a parent page, for example.
@danielroe Thanks for the prompt reply. Yes that’s one strategy, but I was wondering how to go about that for top level directory pages (without nesting). 🤔