feat: 新增重置密码页面
This commit is contained in:
@@ -12,7 +12,11 @@ import {
|
||||
} from "react-router-dom";
|
||||
import { getStorageFromKey } from "@/utils/localStorage/config.ts";
|
||||
|
||||
//递归查询对应的路由
|
||||
/**
|
||||
* 递归查询对应的路由
|
||||
* @param path
|
||||
* @param routes
|
||||
*/
|
||||
export function searchRouteDetail(path: string, routes: RouteObject[]): RouteObject | null {
|
||||
for (const item of routes) {
|
||||
if (item.path === path) return item;
|
||||
@@ -23,7 +27,12 @@ export function searchRouteDetail(path: string, routes: RouteObject[]): RouteObj
|
||||
return null;
|
||||
}
|
||||
|
||||
//全局路由守卫
|
||||
/**
|
||||
* 全局路由守卫
|
||||
* @param location
|
||||
* @param navigate
|
||||
* @param routes
|
||||
*/
|
||||
async function guard(location: Location, navigate: NavigateFunction, routes: RouteObject[]) {
|
||||
const { pathname } = location;
|
||||
|
||||
@@ -40,7 +49,8 @@ async function guard(location: Location, navigate: NavigateFunction, routes: Rou
|
||||
routerDetail.path !== "/login" &&
|
||||
routerDetail.path !== "/register" &&
|
||||
routerDetail.path !== "/" &&
|
||||
routerDetail.path !== "/404"
|
||||
routerDetail.path !== "/404" &&
|
||||
routerDetail.path !== "/forget"
|
||||
) {
|
||||
const token: string | null = getStorageFromKey("token");
|
||||
if (!token) {
|
||||
@@ -52,6 +62,11 @@ async function guard(location: Location, navigate: NavigateFunction, routes: Rou
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 路由守卫
|
||||
* @param routes
|
||||
* @constructor
|
||||
*/
|
||||
export const RouterGuard = (routes: RouteObject[]) => {
|
||||
const location: Location<any> = useLocation();
|
||||
const navigate: NavigateFunction = useNavigate();
|
||||
|
||||
11
src/router/modules/forget/index.ts
Normal file
11
src/router/modules/forget/index.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/** @format */
|
||||
|
||||
import { lazy } from "react";
|
||||
|
||||
const forget = lazy(
|
||||
() =>
|
||||
new Promise((resolve: any) => {
|
||||
setTimeout(() => resolve(import("@/views/User/Forget")), 500);
|
||||
}),
|
||||
);
|
||||
export default forget;
|
||||
@@ -9,6 +9,7 @@ import home from "./modules/home/index.ts";
|
||||
import Main from "./modules/main/index.ts";
|
||||
import ComponentLoading from "@/components/ComponentLoading";
|
||||
import Loading from "./modules/loading";
|
||||
import Forget from "@/router/modules/forget";
|
||||
|
||||
const routes: RouteObject[] = [
|
||||
{
|
||||
@@ -27,6 +28,10 @@ const routes: RouteObject[] = [
|
||||
path: "/login",
|
||||
Component: (props) => ComponentLoading(Login, props),
|
||||
},
|
||||
{
|
||||
path: "/forget",
|
||||
Component: (props) => ComponentLoading(Forget, props),
|
||||
},
|
||||
{
|
||||
path: "/main",
|
||||
Component: (props) => ComponentLoading(Main, props),
|
||||
|
||||
Reference in New Issue
Block a user