Skip to content

Commit

Permalink
feat: remove base_path after login if 404 (close AlistGo/alist#5379)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Dec 17, 2023
1 parent ac8bfe0 commit 2cfcc5b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/hooks/usePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getPagination,
objStore,
recoverScroll,
me,
} from "~/store"
import {
fsGet,
Expand All @@ -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,
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 2cfcc5b

Please sign in to comment.