Skip to content

Commit

Permalink
fix: href of item if basePath is not / (close alist-org/alist#1748)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 22, 2022
1 parent baf74de commit b093cd7
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions src/hooks/useRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,48 @@ import {
useNavigate,
useParams,
useSearchParams,
} from "@solidjs/router";
import { createMemo } from "solid-js";
import {
encodePath,
joinBase,
log,
pathDir,
pathJoin,
trimBase,
} from "~/utils";
} from "@solidjs/router"
import { createMemo } from "solid-js"
import { encodePath, joinBase, log, pathDir, pathJoin, trimBase } from "~/utils"

const useRouter = () => {
const navigate = useNavigate();
const location = useLocation();
const [searchParams, setSearchParams] = useSearchParams();
const params = useParams();
const navigate = useNavigate()
const location = useLocation()
const [searchParams, setSearchParams] = useSearchParams()
const params = useParams()
const pathname = createMemo(() => {
return trimBase(location.pathname)
})
return {
to: (
path: string,
ignore_root?: boolean,
options?: Partial<NavigateOptions>
) => {
if (!ignore_root && path.startsWith("/")) {
path = joinBase(path);
path = joinBase(path)
}
log("to:", path);
navigate(path, options);
log("to:", path)
navigate(path, options)
},
replace: (to: string) => {
navigate(encodePath(pathJoin(pathDir(location.pathname), to), true));
navigate(encodePath(pathJoin(pathDir(location.pathname), to), true))
},
pushHref: (to: string): string => {
return encodePath(pathJoin(location.pathname, to));
const href = encodePath(pathJoin(pathname(), to))
return href
},
back: () => {
navigate(-1);
navigate(-1)
},
forward: () => {
navigate(1);
navigate(1)
},
pathname: createMemo(() => {
return trimBase(location.pathname);
}),
pathname: pathname,
searchParams: searchParams,
setSearchParams: setSearchParams,
params: params,
};
};
}
}

export { useRouter };
export { useRouter }

0 comments on commit b093cd7

Please sign in to comment.