From 2cfcc5b52d90b9b35e56ba067e49cacd068605b6 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Sun, 17 Dec 2023 16:32:32 +0800 Subject: [PATCH] feat: remove base_path after login if 404 (close alist-org/alist#5379) --- src/hooks/usePath.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/hooks/usePath.ts b/src/hooks/usePath.ts index 2f23ca98a..fe93febff 100644 --- a/src/hooks/usePath.ts +++ b/src/hooks/usePath.ts @@ -7,6 +7,7 @@ import { getPagination, objStore, recoverScroll, + me, } from "~/store" import { fsGet, @@ -19,6 +20,8 @@ import { import { useFetch } from "./useFetch" import { useRouter } from "./useRouter" +let first_fetch = true + let cancelList: Canceler export function addOrUpdateQuery( key: string, @@ -75,7 +78,7 @@ export const resetGlobalPage = () => { console.log("resetGlobalPage", globalPage) } export const usePath = () => { - const { pathname } = useRouter() + const { pathname, to } = useRouter() const [, getObj] = useFetch((path: string) => fsGet(path, password())) const pagination = getPagination() if (pagination.type === "pagination" && getQueryVariable("page")) { @@ -204,6 +207,11 @@ export const usePath = () => { notify.error(msg) } } else { + if (first_fetch && msg.endsWith("object not found")) { + first_fetch = false + to(pathname().replace(me().base_path, "")) + return + } ObjStore.setErr(msg) } }