Basically I'm trying to either dynamically select a component for a matched route or have an internal rewrite so I can select a different route without changing url.
My solution right now:
I have url's from an external resource I want to match, I'm catching these with a wildcard page in Nuxt using a _.js
. In a middleware on this page I will determine the actual type of the page it should be (cmspage, productdetail, etc.) and place the result in the store. Then I would check if the data is found in the validate function so I can return a 404 if needed. If successful, would then use the render function to render components/pages/cms.vue
or whatever type of page.
So this should work (still need most of the implementation) but it has the problem that I can't use a lot of Nuxt features (middleware, asyncData, fetch, validate, more?) that are available for pages which is exactly what I'm trying to achieve.
This nuxt config extension doesn't work but would be perfect:
{
router: {
extendRoutes(routes, resolve) {
routes.push({
path: '*',
component: async () => {
const pageType = 'pdp' // await getPageType()
switch (pageType) {
case 'cms':
return resolve(__dirname, 'pages/cmsPage.vue')
case 'pdp':
return resolve(__dirname, 'pages/productDetailPage.vue')
case 'plp':
return resolve(__dirname, 'pages/productListPage.vue')
}
}
})
}
}
}
pageType
?. Does the URL determine what kind of page to display ? – ajobiproduct/product-name
and other under a completely different slug – ajobi