middleware on nested routes
I have an
admin/
route with its index.vue
page and algo nested routes:
admin/users
admin/users/[id]
I added a middleware in the root admin page but the nested routes don't inherit the middleware9 Replies
This is expected behaviour
You can either add it on all page files under the admin folder or assign the middleware to all pages in the folder in a hook
pages:extends
from top of my head@nandi95 are you sure about that? I'm currently trying, and it seems I can protect a subset of routes defining a middleware on parent, ie:
`
yeah I'm sure, I'm open to be proven wrong tho
Nuxt
middleware · Nuxt Directory Structure
Nuxt provides middleware to run code before navigating to a particular route.
you need to add the middleware in
/pages/admin.vue
then both /pages/admin/index.vue
and /pages/admin/[id].vue
should inherit it
/pages/admin.vue
rendering <NuxtPage />
@Cake ohh I thought about it but didn't try it, using an
admin.vue
as some sort of layout and nest the other pages just like vue-router
Gonna give it a try, thx@nandi95 any idea about how I can write a test to test this behavior, other than e2e?
Nuxt unit testing sets up nuxt and runs plugins middlewares etc
You could use an env var or runtime config to bypass but I’d be careful