feat: add handling of external linking in My Pages Navigation

This commit is contained in:
Arvid Norlin
2024-05-03 10:33:35 +02:00
parent ff8053c13a
commit bfaacd7b5d
5 changed files with 18 additions and 5 deletions

View File

@@ -13,6 +13,7 @@ export function mapMenuItems(navigationItems: NavigationItem[]) {
subItems: item.sub_items ? mapMenuItems(item.sub_items) : null, subItems: item.sub_items ? mapMenuItems(item.sub_items) : null,
uid: node.system.uid, uid: node.system.uid,
url: `/${node.system.locale}/${node.url}`.replaceAll(/\/\/+/g, "/"), url: `/${node.system.locale}/${node.url}`.replaceAll(/\/\/+/g, "/"),
originalUrl: node.web?.original_url,
} }
}) })
} }

View File

@@ -34,7 +34,11 @@ export default async function Sidebar({ lang }: SidebarProps) {
</Title> </Title>
{menuItems.map((item) => ( {menuItems.map((item) => (
<Fragment key={item.uid}> <Fragment key={item.uid}>
<Link href={item.url} partialMatch variant="sidebar"> <Link
href={item.originalUrl || item.url}
partialMatch
variant="sidebar"
>
{item.linkText} {item.linkText}
</Link> </Link>
{item.subItems {item.subItems
@@ -42,7 +46,7 @@ export default async function Sidebar({ lang }: SidebarProps) {
return ( return (
<Link <Link
key={subItem.uid} key={subItem.uid}
href={subItem.url} href={subItem.originalUrl || subItem.url}
partialMatch partialMatch
variant="sidebar" variant="sidebar"
> >

View File

@@ -5,4 +5,7 @@ fragment ContentPageLink on ContentPage {
} }
title title
url url
web {
original_url
}
} }

View File

@@ -5,4 +5,7 @@ fragment LoyaltyPageLink on LoyaltyPage {
} }
title title
url url
web {
original_url
}
} }

View File

@@ -15,6 +15,7 @@ export type MenuItem = {
subItems: MenuItem[] | null subItems: MenuItem[] | null
uid: string uid: string
url: string url: string
originalUrl: string | undefined
} }
export type SidebarProps = { export type SidebarProps = {
@@ -28,6 +29,7 @@ interface NavigationLink {
} }
url: string url: string
title: string title: string
web?: { original_url: string }
} }
export interface AccountPageLink export interface AccountPageLink