124
This commit is contained in:
@ -471,7 +471,17 @@ export const publicRoutes = [
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: publicRoutes
|
||||
routes: [...publicRoutes, ...privateRoutes]
|
||||
});
|
||||
|
||||
// 添加路由守卫
|
||||
router.beforeEach((to, from, next) => {
|
||||
const token = store.getters.token;
|
||||
if (!token && to.path !== '/login') {
|
||||
next('/login');
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
//初始化路由表
|
||||
export function resetRouter() {
|
||||
|
||||
@ -14,11 +14,11 @@ service.interceptors.request.use(
|
||||
// 请求接口之前 做些什么
|
||||
//1.统一注入token
|
||||
if (store.getters.token) {
|
||||
// if (isCheckTimeout()) {
|
||||
// //超时 执行退出
|
||||
// store.dispatch('user/logout');
|
||||
// return Promise.reject(new Error('token 失效'));
|
||||
// }
|
||||
if (isCheckTimeout()) {
|
||||
//超时 执行退出
|
||||
store.dispatch('user/logout');
|
||||
return Promise.reject(new Error('token 失效'));
|
||||
}
|
||||
if (!config.url.startsWith("/jcApi")) {
|
||||
config.headers.Authorization = `${store.getters.token}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user