I have an app using Create Next App with SSR using the Prismic API as a content source. I am trying to create dynamic routes and running into a brick wall. Singleton routes were fine but trying to dynamically create routes I can't seem to figure it out.
My Component where I wait to recieve props
class AboutPage extends React.Component {
static async getInitialProps(context) {
const { slug } = context.query;
const response = await getAboutPage(slug);
return {
doc: response,
slices: response.results[0].data.body,
data: response.results[0].data,
};
}
My query where I attempt to get my page data based off the UID:
const getAboutPage = slug => {
try {
const API = Prismic.api(PRISMIC_API_URL);
const response = API.query([
Prismic.Predicates.at('document.tags', [SOURCE]),
Prismic.Predicates.at('my.about_page.uid', slug),
]);
return response;
} catch (error) {
return error;
}
};
My Prismic Link Resolver, but not sure this is relevant
function linkResolver(doc) {
if (doc.type === 'home_page') return `/`;
if (doc.type === 'pricing_page') return `/pricing`;
if (doc.type === 'service_page') return `/services/${doc.uid}`;
if (doc.type === 'about_page') return `/${doc.uid}`;
if (doc.type === 'resource_page') return `/resources/${doc.uid}`;
return '/';
}