fix catch-all routing for generic pages

This commit is contained in:
2024-05-10 20:56:12 +02:00
parent 6baa7cb04e
commit 4a5ae2d7bc

View File

@ -2,9 +2,9 @@ import { graphql } from "@/gql";
import { GenericFragment } from "@/gql/graphql";
import { getClient } from "@/app/client";
import { Blocks } from "@/components/blocks/Blocks";
import { notFound } from 'next/navigation'
import { notFound } from "next/navigation";
export const dynamicParams = false
export const dynamicParams = false;
const GenericFragmentDefinition = graphql(`
fragment Generic on GenericPage {
@ -37,19 +37,20 @@ export async function generateStaticParams() {
return data?.pages.map((page: any) => {
// wagtail-grapple prepends the home page slug to the full path on multisite setups
// we also strip the trailing slash
const urlPath = page.urlPath.replace(/\/home/, "").replace(/\/$/, "");
console.log("adding", urlPath);
const urlPath = page.urlPath
.replace(/\/home\//, "")
.replace(/\/$/, "")
.split("/");
return {
url: [urlPath],
url: urlPath,
};
});
}
export default async function Page({ params }: { params: { url: string } }) {
export default async function Page({ params }: { params: { url: string[] } }) {
const { url } = params;
// for the page /foo/bar we need to look for `/home/foo/bar/`
const urlPath = `/home/${url}/`;
console.log("real urlPath for", url, "is", urlPath);
const urlPath = `/home/${url.join("/")}/`;
const genericPageByUrlPathQuery = graphql(`
query genericPageByUrl($urlPath: String!) {
@ -65,11 +66,10 @@ export default async function Page({ params }: { params: { url: string } }) {
urlPath: urlPath,
});
const page = (data?.page ?? []) as GenericFragment[];
if (!page) {
return notFound()
return notFound();
}
return (