Hey everyone! Im kind of stuck with my routing strategy. So my pages directory looks like this:
pages
├── [category]
│ ├── index.vue
│ ├── [sub_category]
│ │ ├── index.vue
│ │ └── [handle]
│ │ └── index.vue
In the case a category doesn't have a sub_category, I extended the routes in the nuxt.config.ts through hooks like that:
hooks: {
'pages:extend': function (pages) {
pages.push({
name: 'category-handle',
path: '/:category/:handle',
file: '~/pages/[category]/[sub_category]/[handle]/index.vue',
})
},
},
Now when navigating through the app, everything works as expected. The issue is when reloading or remounting the page on such a route (/somecategory/someproduct, as instead of rendering the page defined in the hooks property, the index.vue from the [sub_category] directory gets rendered. I figured it's becasue there's always the sub_category getting passed as a param instead of handle (I mean how should it know?).
Here's a small reproduction: https://stackblitz.com/edit/nuxt-starter-fxkfp1?file=app.vue
If you navigate to "Handle without Subcat" and hit reload, that's the issue I mean.
I already kind of tried to solve this with a middlware, but all I fabricated was an infinite redirect 😅
Has somebody faced a similiar problem, or can someone maybe point me into the right direction?
I appreciate you help 😊