feat: 优化页面保护逻辑,提取 guarded page 检查函数
This commit is contained in:
@@ -11,11 +11,15 @@ import type { LayoutLoad } from "./$types";
|
|||||||
// See: https://v2.tauri.app/start/frontend/sveltekit/ for more info
|
// See: https://v2.tauri.app/start/frontend/sveltekit/ for more info
|
||||||
export const ssr = false;
|
export const ssr = false;
|
||||||
|
|
||||||
|
function isGuardedPage(pathname: string) {
|
||||||
|
return !pathname.startsWith("/boot") && !pathname.startsWith("/settings") && !pathname.startsWith("/create");
|
||||||
|
}
|
||||||
|
|
||||||
export const load: LayoutLoad = async ({url}) => {
|
export const load: LayoutLoad = async ({url}) => {
|
||||||
const currentOpenedDataset = get(openedDatasetDir);
|
const currentOpenedDataset = get(openedDatasetDir);
|
||||||
console.debug('[Main Load]', currentOpenedDataset, url);
|
console.debug('[Main Load]', currentOpenedDataset, url);
|
||||||
|
|
||||||
if (isNil(currentOpenedDataset) && url.pathname !== "/boot" && url.pathname !== "/settings") {
|
if (isNil(currentOpenedDataset) && isGuardedPage(url.pathname)) {
|
||||||
redirect(303, "/boot");
|
redirect(303, "/boot");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user