From c13211010f4064f85034d3d61131b2a58364411b Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Thu, 15 Aug 2024 12:29:19 +0300 Subject: [PATCH 01/10] Add missing layoutBehavior --- packages/commons-ui-next/src/Link/Link.js | 47 ++++++++--------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/packages/commons-ui-next/src/Link/Link.js b/packages/commons-ui-next/src/Link/Link.js index b8e73dbe9..5356e339e 100644 --- a/packages/commons-ui-next/src/Link/Link.js +++ b/packages/commons-ui-next/src/Link/Link.js @@ -14,14 +14,23 @@ const Anchor = styled("a")({}); export const NextLinkComposed = React.forwardRef( function NextLinkComposed(props, ref) { - const { linkAs, locale, prefetch, replace, scroll, shallow, to, ...other } = - props; + const { + linkAs, + locale, + prefetch, + legacyBehavior = true, + replace, + scroll, + shallow, + to, + ...other + } = props; return ( Date: Thu, 15 Aug 2024 12:30:12 +0300 Subject: [PATCH 02/10] Include page slug in returned page data --- apps/roboshield/src/lib/data/common/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/roboshield/src/lib/data/common/index.ts b/apps/roboshield/src/lib/data/common/index.ts index 85fd15142..e384b0ef8 100644 --- a/apps/roboshield/src/lib/data/common/index.ts +++ b/apps/roboshield/src/lib/data/common/index.ts @@ -50,16 +50,15 @@ export async function getPageProps( api: Api, context: GetServerSidePropsContext, ) { - const { resolvedUrl } = context; - let path; - if (resolvedUrl === "/" || resolvedUrl === "") { - path = "index"; - } else { - path = resolvedUrl.replace(/^\//, ""); - } + // For now, RoboShield only supports single paths i.e. /, /about, etc., + // so params.slug[0] is good enough + const { + params: { slug: slugs }, + } = context; + const [slug] = slugs || ["index"]; const { docs: [page], - } = await api.findPage(path); + } = await api.findPage(slug); if (!page) { return null; @@ -74,6 +73,7 @@ export async function getPageProps( blocks, footer, navbar, + slug, }; } From ed17cb0e2ece1ed670bebaab8c66a06b5ae72cc7 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Thu, 15 Aug 2024 12:31:12 +0300 Subject: [PATCH 03/10] Re-render main component on page change --- apps/roboshield/src/components/Page/Page.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/roboshield/src/components/Page/Page.tsx b/apps/roboshield/src/components/Page/Page.tsx index 70ebfe716..f2eb50082 100644 --- a/apps/roboshield/src/components/Page/Page.tsx +++ b/apps/roboshield/src/components/Page/Page.tsx @@ -30,12 +30,18 @@ interface Props { children?: React.ReactNode; navbar?: Navbar; footer?: FooterProps; + slug?: string; } -function Page({ children, navbar, footer }: Props) { + +/** + * While the layout (navbar, footer) remain the same, the main component + * changes from page to page. Use `slug` to track page changes. + */ +function Page({ children, footer, navbar, slug }: Props) { return ( <> {navbar ? : null} - {children ?
{children}
: null} + {children ?
{children}
: null} {footer ?