Commit 01b63a8f authored by 前端-钟卫鹏's avatar 前端-钟卫鹏
parents 42951395 e62623ae
......@@ -38,12 +38,13 @@ const memberCenterRoute = {
},
...routes,
{
path: '/noAuth',
path: '/memberCenter/noAuth',
auth: false,
component: '@/pages/403',
},
// 能力中心的404页
{
path: '/*',
auth: false,
component: '@/pages/404',
},
......
......@@ -22,13 +22,16 @@ const whiteLists = [
'/user/login',
'/user/register',
'/memberCenter',
'/memberCenter/noAuth',
'/commodity',
'/shops',
'/shop/commodity/detail',
'/shop/commodity',
'/shop',
'/infomation',
'/403',
'/404',
'/500',
'/noAuth'
]
......@@ -70,10 +73,12 @@ export function render(oldRender: Function) {
token: data.token
})
setRouters(data.urls)
oldRender()
})
} else {
history.push('/user/login')
oldRender()
}
oldRender()
}
/**
......@@ -84,21 +89,20 @@ export function render(oldRender: Function) {
* @param {*} { routes, matchedRoutes, location, action }
*/
export function onRouteChange({ routes, matchedRoutes, location, action }) {
console.log(`当前可访问的路由为`)
console.log(routes, matchedRoutes, location)
console.log('onRouteChange')
if (isDev) {
return;
}
if (whiteLists.includes(location.pathname)) return;
const routeAuthUrls = getRouters()
console.log(routeAuthUrls, "routeAuthUrls")
// 是否登录
if (getAuth()) {
if (routeAuthUrls.includes(location.pathname)) {
} else {
// history.replace('/')
// 无权限访问时
history.replace('/memberCenter/noAuth')
}
} else {
history.replace('/user/login')
......
......@@ -14,7 +14,6 @@ const NoFoundPage: React.FC<{}> = () => {
return (
<div className={styles.wrapper}>
<UserHeader logo={GlobalConfig.global.logo}/>
<div className={styles.errorBox}>
<Row>
<Col span={12}>
......
......@@ -23,7 +23,8 @@ const LoginWrap: React.FC = () => {
token: data.token
})
setRouters(data.urls)
history.push('/memberCenter/home')
// 此处需使用href跳转, 否则无法触发app.ts中的路由初始化校验
window.location.href = '/memberCenter/home'
})
}
......
......@@ -4,6 +4,7 @@ import { IRequestError, IRequestSuccess } from '..';
import { history } from 'umi'
import { message } from 'antd'
import { getAuth, removeAuth } from './auth';
import { GlobalConfig } from '@/global/config';
export type CtlType = 'none' | 'message'
// 根前缀请求路径
......@@ -52,7 +53,8 @@ const errorHandler = (error: ResponseError): IRequestError => {
const defaultHeaders = {
'Content-Type': 'Application/json',
'source': '1'
'source': '1',
'site': GlobalConfig.global.siteId.toString()
}
/**
......
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