From 96bad151695e62ce7c098ffb705a3ae1ccce9178 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Fri, 11 Oct 2024 11:02:17 +0200 Subject: [PATCH] fix(link): broken links and root fix --- src/app/(main)/[lang]/page.tsx | 2 +- src/components/utils/linkTypes.ts | 2 +- src/utils/get.tsx | 13 +++---------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/app/(main)/[lang]/page.tsx b/src/app/(main)/[lang]/page.tsx index 1de91ca7f..a26193826 100644 --- a/src/app/(main)/[lang]/page.tsx +++ b/src/app/(main)/[lang]/page.tsx @@ -30,7 +30,7 @@ const navigationManagerLink = { _type: "link", linkTitle: "Go to Navigation Manager", linkType: LinkType.Internal, - internalLink: { _ref: "studio/structure/navigationManager" }, + internalLink: { _ref: "studio/structure/siteSettings;navigationManager" }, }; const pagesLink = { diff --git a/src/components/utils/linkTypes.ts b/src/components/utils/linkTypes.ts index ccf624ddb..85fec0206 100644 --- a/src/components/utils/linkTypes.ts +++ b/src/components/utils/linkTypes.ts @@ -6,7 +6,7 @@ export const homeLink = { linkTitle: "Return to home", linkType: LinkType.Internal, internalLink: { - _ref: "/", + _ref: "", }, }; diff --git a/src/utils/get.tsx b/src/utils/get.tsx index b281c4e34..3971dec98 100644 --- a/src/utils/get.tsx +++ b/src/utils/get.tsx @@ -3,15 +3,10 @@ import { ILink, LinkType } from "studio/lib/interfaces/navigation"; const hash = "#"; export const getHref = (link: ILink): string => { - switch (link?.linkType) { + switch (link.linkType) { case LinkType.Internal: - if (link.internalLink?._ref) { - try { - return `${link.language ? `/${link.language}` : ""}/${link.internalLink._ref}${link.anchor ? `#${link.anchor}` : ""}`; - } catch (error) { - console.error("Error fetching page:", error); - return hash; - } + if (link.internalLink?._ref !== undefined) { + return `${link.language ? `/${link.language}` : ""}/${link.internalLink._ref}${link.anchor ? `#${link.anchor}` : ""}`; } return hash; case LinkType.External: @@ -20,7 +15,5 @@ export const getHref = (link: ILink): string => { return `mailto:${link.email}`; case LinkType.Phone: return `tel:${link.phone}`; - default: - return hash; } };