Hello,
I am currently developping a website under next Js, and with time it started taking a little bit more complexity.
At the moment we have a page structure that looks like this
pages/[uid].js
But in an effort to organize everything, we decided to move forward with nested routes; I am using a SliceZone for the components, but currently I have a Link Resolver, I feed the link object
that looks like this
{
"id": "YGH1sBAAACEAGGjF",
"type": "page",
"tags": [
"Products"
],
"slug": "product-slug",
"lang": "de-de",
"uid": "product-slug",
"link_type": "Document",
"isBroken": false
}
My link resolver would check the type and the lang, and resolve accordingly the proper route.
The link resolver looks like this
linkResolver(doc) {
console.log({ doc });
if (doc.type === 'page') {
return `/${doc.lang}/${doc.uid}`;
}
if (doc.type === 'homepage') {
return `/${doc.lang}`;
}
if (doc.type === 'services') {
return `/${doc.lang}/services/${doc.uid}`;
}
return '/';
},
But the problem now is that I defined a Relational Link on my pages, that link to a category in order to create a route in a form of
pages/[category]/[uid].js
Fetching and filtering the pages wasn't a problem. The routing now is, as I have a Link Resolver routing, there is no way for me to know what is the category relation with a certain page.
I have checked Define Paths with Next.js - Prismic
I have already have in my template a Router in my prismic.js
But I feel this is only for nuxt js as I don't see it being called anywhere and it doesn't feel like next js code.
export const Router = {
routes: [
{ type: 'page', path: '/:uid' },
],
href: (type) => {
const route = Router.routes.find((r) => r.type === type);
return route && route.href;
},
};