fix catch-all routing for generic pages
This commit is contained in:
@ -2,9 +2,9 @@ import { graphql } from "@/gql";
|
|||||||
import { GenericFragment } from "@/gql/graphql";
|
import { GenericFragment } from "@/gql/graphql";
|
||||||
import { getClient } from "@/app/client";
|
import { getClient } from "@/app/client";
|
||||||
import { Blocks } from "@/components/blocks/Blocks";
|
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(`
|
const GenericFragmentDefinition = graphql(`
|
||||||
fragment Generic on GenericPage {
|
fragment Generic on GenericPage {
|
||||||
@ -37,19 +37,20 @@ export async function generateStaticParams() {
|
|||||||
return data?.pages.map((page: any) => {
|
return data?.pages.map((page: any) => {
|
||||||
// wagtail-grapple prepends the home page slug to the full path on multisite setups
|
// wagtail-grapple prepends the home page slug to the full path on multisite setups
|
||||||
// we also strip the trailing slash
|
// we also strip the trailing slash
|
||||||
const urlPath = page.urlPath.replace(/\/home/, "").replace(/\/$/, "");
|
const urlPath = page.urlPath
|
||||||
console.log("adding", urlPath);
|
.replace(/\/home\//, "")
|
||||||
|
.replace(/\/$/, "")
|
||||||
|
.split("/");
|
||||||
return {
|
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;
|
const { url } = params;
|
||||||
// for the page /foo/bar we need to look for `/home/foo/bar/`
|
// for the page /foo/bar we need to look for `/home/foo/bar/`
|
||||||
const urlPath = `/home/${url}/`;
|
const urlPath = `/home/${url.join("/")}/`;
|
||||||
console.log("real urlPath for", url, "is", urlPath);
|
|
||||||
|
|
||||||
const genericPageByUrlPathQuery = graphql(`
|
const genericPageByUrlPathQuery = graphql(`
|
||||||
query genericPageByUrl($urlPath: String!) {
|
query genericPageByUrl($urlPath: String!) {
|
||||||
@ -65,11 +66,10 @@ export default async function Page({ params }: { params: { url: string } }) {
|
|||||||
urlPath: urlPath,
|
urlPath: urlPath,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const page = (data?.page ?? []) as GenericFragment[];
|
const page = (data?.page ?? []) as GenericFragment[];
|
||||||
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
return notFound()
|
return notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user