Skip to content

Commit

Permalink
feat: Implement LinkHandler for dynamic link management in Navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
MBeggiato committed Nov 7, 2024
1 parent 1c1e2d7 commit 49ff8cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/lib/LinkHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { base } from '$app/paths'

export const LinkHandler = (link: string) => {
if (process.env.NODE_ENV === 'development') {
return link
}

if (link === '/') {
return base
}

return base + link
}
5 changes: 3 additions & 2 deletions src/lib/components/Navbar.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
import { LinkHandler } from '$lib/LinkHandler';
import {
Navbar,
NavBrand,
Expand All @@ -13,7 +14,7 @@
</script>

<Navbar>
<NavBrand href="/">
<NavBrand href={LinkHandler('/')}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="32"
Expand Down Expand Up @@ -53,7 +54,7 @@
<DarkMode class="ml-2" />
</div>
<NavUl>
<NavLi href="/">Home</NavLi>
<NavLi href={LinkHandler('/')}>Home</NavLi>
<!--
<NavLi href="/about">About</NavLi>
<NavLi href="/docs/components/navbar">Navbar</NavLi>
Expand Down

0 comments on commit 49ff8cc

Please sign in to comment.