mirror of
https://github.com/Lapikud/lapikud.github.io.git
synced 2026-08-09 07:29:14 +00:00
updated and fixed most pages + navbar update on home page
This commit is contained in:
@@ -11,7 +11,23 @@
|
||||
let { routes } = $props();
|
||||
|
||||
let currentPath = $state(window.location.pathname);
|
||||
let CurrentComponent = $derived(routes[currentPath] || routes["/"]);
|
||||
let CurrentComponent = $state(null);
|
||||
|
||||
async function resolveCurrentComponent(path) {
|
||||
const routeEntry = routes[path] || routes["/"];
|
||||
|
||||
if (typeof routeEntry === "function") {
|
||||
try {
|
||||
const module = await routeEntry();
|
||||
CurrentComponent = module?.default || null;
|
||||
} catch {
|
||||
CurrentComponent = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentComponent = routeEntry || null;
|
||||
}
|
||||
|
||||
function navigate(path) {
|
||||
window.history.pushState({}, "", path);
|
||||
@@ -46,6 +62,10 @@
|
||||
|
||||
return () => window.removeEventListener("click", handleClick);
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
resolveCurrentComponent(currentPath);
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if CurrentComponent}
|
||||
|
||||
Reference in New Issue
Block a user