Redirect / til første workspace-side automatisk
Både workspace-switch og direkte navigering til rot-URL lander nå på første konfigurerte side i stedet for tom oversikt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a93ffc6de5
commit
7c5b809802
1 changed files with 13 additions and 0 deletions
|
|
@ -1,8 +1,15 @@
|
|||
import type { PageServerLoad } from './$types';
|
||||
import type { PageConfig } from '$lib/types/pages';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
const WORKSPACE_COOKIE = 'sidelinja_workspace';
|
||||
|
||||
function getFirstPageSlug(workspace: { settings?: unknown } | null): string | null {
|
||||
const settings = workspace?.settings as Record<string, unknown> | undefined;
|
||||
const pages = (settings?.pages as PageConfig[]) ?? [];
|
||||
return pages[0]?.slug ?? null;
|
||||
}
|
||||
|
||||
export const load: PageServerLoad = async ({ url, cookies, locals }) => {
|
||||
const switchTo = url.searchParams.get('switch_workspace');
|
||||
|
||||
|
|
@ -16,7 +23,13 @@ export const load: PageServerLoad = async ({ url, cookies, locals }) => {
|
|||
sameSite: 'lax',
|
||||
maxAge: 60 * 60 * 24 * 365
|
||||
});
|
||||
const firstPage = getFirstPageSlug(ws);
|
||||
if (firstPage) redirect(303, `/p/${firstPage}`);
|
||||
}
|
||||
redirect(303, '/');
|
||||
}
|
||||
|
||||
// Vanlig landing på / — redirect til første side
|
||||
const firstPage = getFirstPageSlug(locals.workspace);
|
||||
if (firstPage) redirect(303, `/p/${firstPage}`);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue