web/routes: refactor error & /about/[page] to svelte 5

This commit is contained in:
wukko 2025-06-03 11:18:42 +06:00
parent 58209970ac
commit b304549a8d
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2
2 changed files with 13 additions and 16 deletions

View File

@ -1,14 +1,14 @@
<script lang="ts">
import { onMount } from "svelte";
import { page } from "$app/stores";
import { page } from "$app/state";
import { goto } from "$app/navigation";
import { defaultNavPage } from "$lib/subnav";
onMount(() => {
if ($page.error?.message === "Not Found") {
if ($page.url.pathname.startsWith("/settings")) {
if (page.error?.message === "Not Found") {
if (page.url.pathname.startsWith("/settings")) {
goto(defaultNavPage("settings"), { replaceState: true });
} else if ($page.url.pathname.startsWith("/about")) {
} else if (page.url.pathname.startsWith("/about")) {
goto(defaultNavPage("about"), { replaceState: true });
} else {
goto("/", { replaceState: true });

View File

@ -1,14 +1,13 @@
import type { ComponentType, SvelteComponent } from 'svelte';
import { get } from 'svelte/store';
import { error } from '@sveltejs/kit';
import locale from "$lib/i18n/locale";
import { get } from "svelte/store";
import { error } from "@sveltejs/kit";
import { defaultLocale } from "$lib/i18n/translations";
import type { PageLoad } from './$types';
import type { Component } from "svelte";
import type { PageLoad } from "./$types";
import type { DefaultImport } from "$lib/types/generic";
import locale from '$lib/i18n/locale';
import type { DefaultImport } from '$lib/types/generic';
import { defaultLocale } from '$lib/i18n/translations';
const pages = import.meta.glob('$i18n/*/about/*.md');
const pages = import.meta.glob("$i18n/*/about/*.md");
export const load: PageLoad = async ({ params }) => {
const getPage = (locale: string) => Object.keys(pages).find(
@ -17,13 +16,11 @@ export const load: PageLoad = async ({ params }) => {
const componentPath = getPage(get(locale)) || getPage(defaultLocale);
if (componentPath) {
type Component = ComponentType<SvelteComponent>;
const componentImport = pages[componentPath] as DefaultImport<Component>;
return { component: (await componentImport()).default }
}
error(404, 'Not found');
error(404, 'Not found');
};
export const prerender = true;