mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-27 17:08:28 +00:00
web/routes: refactor error & /about/[page] to svelte 5
This commit is contained in:
parent
58209970ac
commit
b304549a8d
@ -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 });
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user