feat: update

This commit is contained in:
landaiqing
2024-05-29 21:33:58 +08:00
parent cb9c827220
commit 4ce065214a
11 changed files with 173 additions and 144 deletions

View File

@@ -10,7 +10,7 @@ import {
useNavigate,
useRoutes,
} from "react-router-dom";
import localforage from "localforage";
import { getStorageFromKey } from "@/utils/localStorage/config.ts";
//递归查询对应的路由
export function searchRouteDetail(path: string, routes: RouteObject[]): RouteObject | null {
@@ -28,21 +28,21 @@ async function guard(location: Location, navigate: NavigateFunction, routes: Rou
const { pathname } = location;
//找到对应的路由信息
const routedetail: RouteObject | null = searchRouteDetail(pathname, routes);
const routerDetail: RouteObject | null = searchRouteDetail(pathname, routes);
//没有找到路由跳转404
if (!routedetail) {
if (!routerDetail) {
navigate("/404");
return false;
}
//如果需要权限验证
if (
routedetail.path !== "/login" &&
routedetail.path !== "/register" &&
routedetail.path !== "/" &&
routedetail.path !== "/404"
routerDetail.path !== "/login" &&
routerDetail.path !== "/register" &&
routerDetail.path !== "/" &&
routerDetail.path !== "/404"
) {
const token: string | null = await localforage.getItem("token");
const token: string | null = getStorageFromKey("token");
if (!token) {
message.warning("请先登录!").then();
navigate("/login");