feat: update
This commit is contained in:
@@ -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");
|
||||
|
Reference in New Issue
Block a user