ModbusPoll下载后如何配置?超详细版测试教程
2025/12/22 23:22:27
构建一个健壮的前端路由系统,不仅仅是把页面配置进去,更要考虑层级结构、权限控制、用户体验(重定向)以及异常兜底(404)。
{path:"/login",component:"LoginPage"},{path:"/",component:"@/widgets/MainLayout",routes:[{path:"/",redirect:"/dashboard"},{path:"/dashboard",component:"DashboardPage",wrappers:["@/wrappers/auth"],},// 其他业务页面...]}import{Navigate,Outlet,useLocation}from"umi";import{isUserLoggedIn}from"@/shared/utils/auth";/** * 路由守卫(第一道防线) * 拦截没有 Token 的用户,并重定向到登录页,传递 reason=no_auth */exportdefault()=>{constlocation=useLocation();constisLogin=isUserLoggedIn();if(isLogin){return<Outlet/>;}else{// 构造目标 URL// 1. redirect: 登录成功后要跳回的地方// 2. reason=no_auth: 告诉登录页,这是因为没登录被拦截过来的constcurrentPath=encodeURIComponent(location.pathname+location.search);consttargetUrl=`/login?redirect=${currentPath}&reason=no_auth`;return<Navigate to={targetUrl}replace/>;}};{path:"*",component:"404"},wrappers: ['@/wrappers/auth']