I am trying to create a dynamic route, where a slug in a post decides what the parent-route should be.
This is inside my _post.vue
file:
export default {
nuxtI18n: {
paths: {
es: '/ayuda/:category/:uid',
en: '/help/:category/:uid',
},
},
async asyncData({ $prismic, params, error, app }) {
const currentLocale = app.i18n.locales.filter(
(lang) => lang.code === app.i18n.locale
)[0];
const result = await $prismic.api.getByUID(
'help_category_post',
params.uid,
{
lang: currentLocale.iso.toLowerCase(),
}
);
if (result) {
return {
post: result.results || result,
currentLocale,
};
} else {
error({ statusCode: 404, message: 'Page not found' });
}
},
};
When you create this post in Prismic, there is a slug field (not the _uid, I'm using content relationship) where you can choose what the route-name should be. For example, if I choose test
in the slug field the route should be /help/test/post-name
.
The slug will then come from the post through post.data.link.slug
.
My question is. How do I make the /:category/
match post.data.link.slug
in this example?
Am I going about this wrong? Is there a better way to decide what parent-route a post should have?