Unverified Commit 83fb5103 authored by yqwoe's avatar yqwoe Committed by GitHub

fix: 前端路由监听修改默认跳转路由; (#2231)

* feat: use-service hooks * fix: 前端路由监听修改默认跳转路由;
parent 582c2263
...@@ -34,6 +34,7 @@ import {Reducer, StoreEnhancer} from 'redux'; ...@@ -34,6 +34,7 @@ import {Reducer, StoreEnhancer} from 'redux';
import { API } from "./services/data"; import { API } from "./services/data";
import {AccessContextProvider} from '@/hooks/useAccess'; import {AccessContextProvider} from '@/hooks/useAccess';
import { Navigate } from 'umi'; import { Navigate } from 'umi';
import {SysMenu} from "@/types/RegCenter/data";
// const isDev = process.env.NODE_ENV === "development"; // const isDev = process.env.NODE_ENV === "development";
const loginPath = API_CONSTANTS.LOGIN_PATH; const loginPath = API_CONSTANTS.LOGIN_PATH;
...@@ -42,7 +43,8 @@ const whiteList = ['/user','/user/login'] ...@@ -42,7 +43,8 @@ const whiteList = ['/user','/user/login']
let extraRoutes; let extraRoutes=[];
let rendered = false;
/** /**
* 初始化路由鉴权 * 初始化路由鉴权
...@@ -193,7 +195,7 @@ export const dva = { ...@@ -193,7 +195,7 @@ export const dva = {
/*** /***
* 动态修改默认跳转路由 * 动态修改默认跳转路由
*/ */
const patch = (oldrRoutes, routes)=>{ const patch = (oldrRoutes, routes: SysMenu[])=>{
oldrRoutes[1].routes = oldrRoutes[1].routes.map(route=>{ oldrRoutes[1].routes = oldrRoutes[1].routes.map(route=>{
if(route.routes && route.routes.length){ if(route.routes && route.routes.length){
const redirect = routes.filter(r=>r.path.startsWith(route.path)) const redirect = routes.filter(r=>r.path.startsWith(route.path))
...@@ -219,19 +221,17 @@ export function patchClientRoutes({ routes }) { ...@@ -219,19 +221,17 @@ export function patchClientRoutes({ routes }) {
} }
/*** /***
* 动态加载路由 * 路由切换并只加载首次
*/ */
export function render(oldRender) { export function onRouteChange({ location, clientRoutes, routes, action }) {
const {location} = history; if (location.pathname !== loginPath && !rendered) {
if (location.pathname !== loginPath) {
const filterMenus = (menus=[])=>{ const filterMenus = (menus=[])=>{
return menus.filter(menu=>menu.type !== 'F') return menus.filter(menu=>menu.type !== 'F')
} }
extraRoutes = filterMenus(extraRoutes)
queryCurrentUser().then(res=>{ patchClientRoutes({routes: clientRoutes})
extraRoutes = filterMenus(res.datas.menuList) rendered = true
oldRender();
})
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment