improved should reload
This commit is contained in:
@@ -28,7 +28,6 @@
|
|||||||
SheetTrigger
|
SheetTrigger
|
||||||
} from '$lib/components/ui/sheet';
|
} from '$lib/components/ui/sheet';
|
||||||
import { cn } from '$lib/utils';
|
import { cn } from '$lib/utils';
|
||||||
import { navigationMenuTriggerStyle } from './ui/navigation-menu/navigation-menu-trigger.svelte';
|
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import { onMount, tick } from 'svelte';
|
import { onMount, tick } from 'svelte';
|
||||||
import { tweened } from 'svelte/motion';
|
import { tweened } from 'svelte/motion';
|
||||||
@@ -116,9 +115,16 @@
|
|||||||
expandedSubmenu = expandedSubmenu === itemName ? null : itemName;
|
expandedSubmenu = expandedSubmenu === itemName ? null : itemName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const reloadPaths = ['/blog/'];
|
||||||
|
|
||||||
|
function shouldReload(url?: string) {
|
||||||
const shouldReload = $derived($page.url.pathname.startsWith('/blog/'));
|
if (!url) return false;
|
||||||
|
const currentPath = $page.url.pathname;
|
||||||
|
|
||||||
|
return reloadPaths.some(path =>
|
||||||
|
url.startsWith(path) && currentPath.startsWith(path)
|
||||||
|
);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<nav class="bg-primary relative z-[50] py-3">
|
<nav class="bg-primary relative z-[50] py-3">
|
||||||
@@ -156,9 +162,7 @@
|
|||||||
'relative z-20 text-white transition-colors hover:text-white/80 focus:bg-white/10 focus:outline-none focus:ring-2 focus:ring-white/20'
|
'relative z-20 text-white transition-colors hover:text-white/80 focus:bg-white/10 focus:outline-none focus:ring-2 focus:ring-white/20'
|
||||||
)}
|
)}
|
||||||
href={item.url}
|
href={item.url}
|
||||||
data-sveltekit-reload={item.url?.startsWith('/blog/') && shouldReload
|
data-sveltekit-reload={shouldReload(item.url) ? true : undefined}
|
||||||
? true
|
|
||||||
: undefined}
|
|
||||||
>
|
>
|
||||||
{item.name}
|
{item.name}
|
||||||
</NavigationMenuLink>
|
</NavigationMenuLink>
|
||||||
@@ -170,9 +174,7 @@
|
|||||||
<NavigationMenuLink
|
<NavigationMenuLink
|
||||||
href={item.url}
|
href={item.url}
|
||||||
class="focus:outline-none"
|
class="focus:outline-none"
|
||||||
data-sveltekit-reload={item.url?.startsWith('/blog/') && shouldReload
|
data-sveltekit-reload={shouldReload(item.url) ? true : undefined}
|
||||||
? true
|
|
||||||
: undefined}
|
|
||||||
>
|
>
|
||||||
{item.name}
|
{item.name}
|
||||||
</NavigationMenuLink>
|
</NavigationMenuLink>
|
||||||
@@ -191,9 +193,7 @@
|
|||||||
<NavigationMenuLink
|
<NavigationMenuLink
|
||||||
href={subitem.url}
|
href={subitem.url}
|
||||||
class="block rounded-md px-4 py-2 text-white transition-colors hover:bg-white/10 hover:text-white/80 focus:bg-white/10 focus:text-white focus:outline-none focus:ring-2 focus:ring-white/20"
|
class="block rounded-md px-4 py-2 text-white transition-colors hover:bg-white/10 hover:text-white/80 focus:bg-white/10 focus:text-white focus:outline-none focus:ring-2 focus:ring-white/20"
|
||||||
data-sveltekit-reload={subitem.url?.startsWith('/blog/') && shouldReload
|
data-sveltekit-reload={shouldReload(subitem.url) ? true : undefined}
|
||||||
? true
|
|
||||||
: undefined}
|
|
||||||
>
|
>
|
||||||
{subitem.name}
|
{subitem.name}
|
||||||
</NavigationMenuLink>
|
</NavigationMenuLink>
|
||||||
@@ -236,9 +236,7 @@
|
|||||||
index === activeIndex && 'bg-white/20'
|
index === activeIndex && 'bg-white/20'
|
||||||
)}
|
)}
|
||||||
onclick={closeMobileMenu}
|
onclick={closeMobileMenu}
|
||||||
data-sveltekit-reload={item.url?.startsWith('/blog/') && shouldReload
|
data-sveltekit-reload={shouldReload(item.url) ? true : undefined}
|
||||||
? true
|
|
||||||
: undefined}
|
|
||||||
>
|
>
|
||||||
{item.name}
|
{item.name}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -281,9 +279,7 @@
|
|||||||
href={item.url}
|
href={item.url}
|
||||||
class="block rounded-md px-6 py-2 text-sm text-white/80 transition-colors hover:text-white focus:outline-none focus:ring-2 focus:ring-white/20"
|
class="block rounded-md px-6 py-2 text-sm text-white/80 transition-colors hover:text-white focus:outline-none focus:ring-2 focus:ring-white/20"
|
||||||
onclick={closeMobileMenu}
|
onclick={closeMobileMenu}
|
||||||
data-sveltekit-reload={item.url?.startsWith('/blog/') && shouldReload
|
data-sveltekit-reload={shouldReload(item.url) ? true : undefined}
|
||||||
? true
|
|
||||||
: undefined}
|
|
||||||
>
|
>
|
||||||
{item.name}
|
{item.name}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -293,9 +289,7 @@
|
|||||||
href={subitem.url}
|
href={subitem.url}
|
||||||
class="block rounded-md px-6 py-2 text-sm text-white/80 transition-colors hover:text-white focus:outline-none focus:ring-2 focus:ring-white/20"
|
class="block rounded-md px-6 py-2 text-sm text-white/80 transition-colors hover:text-white focus:outline-none focus:ring-2 focus:ring-white/20"
|
||||||
onclick={closeMobileMenu}
|
onclick={closeMobileMenu}
|
||||||
data-sveltekit-reload={subitem.url?.startsWith('/blog/') && shouldReload
|
data-sveltekit-reload={shouldReload(subitem.url) ? true : undefined}
|
||||||
? true
|
|
||||||
: undefined}
|
|
||||||
>
|
>
|
||||||
{subitem.name}
|
{subitem.name}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user