I asked another question about dynamic routes here, and Sam was super helpful for getting dynamic routing from content relationships figured out. Currently, I've got my pages directory structured like this:
└── pages
└── [landing]
└── [uid].tsx
└── index.tsx
And my [uid].tsx template looks like this:
import React from 'react';
import { SEO } from 'components/seo/SEO';
import { SliceZone } from 'components/slice-zone/SliceZone';
import Prismic from 'prismic-javascript';
import { Client, queryWithLanguage, queryWithProductsDealers } from '../../lib/prismic';
export const Page = ({ document, city }: any) => {
const { meta_title, meta_description, meta_keywords, social_image } = document.results[0].data;
const slices = document.results[0].data;
const title = `${city} ${meta_title}`;
const description = `${city} ${meta_description}`;
if (!slices) return null;
return (
<>
<SEO
title={title}
description={description}
keywords={meta_keywords}
banner={social_image.url}
/>
<SliceZone slices={slices} />
</>
);
};
export default Page;
export const getServerSideProps = async ({ params }: any) => {
const { uid, landing } = params;
const { id, data: dealer } = await Client.getByUID('dealer', landing, queryWithLanguage);
const document = await Client.query(
[
Prismic.Predicates.at('my.landing.dealers.dealer', id),
Prismic.Predicates.at('my.landing.uid', uid),
],
{lang: 'en-us', fetchLinks: ['product.body', 'dealers.data']}
);
return {
props: {
document,
city: dealer.dealer_location,
},
};
};
So, I'm getting the id of the dealer page that is requested in my params, and then I'm able to pull that data in to pass through getServerSideProps. That being said, I want to go one level deeper...
Essentially, I could have upwards of 75-100 different dealer documents, and each time I create a new page of the type landing I don't want to have to add all of those documents as individual content relationships. So, what I'm wondering is this: is it possible to have a single document, dealers_list for example, with a group field of content relationships that I can use for each dealer, and am I able to query those content relationships in my uid page, allowing for users to access my landing pages at both mysite.com/landing-page and mysite.com/sacramento-ca/interior-doors or mysite.com/denver-co/interior-doors defining the cities in my dealer_list document? See my other question for more clarity about my initial needs. Now that I've gotten that working I guess I'm a glutton for punishment and need more...
Thanks in advance!