Commit f9a2760f authored by 李鹏 's avatar 李鹏

mofigy

parent 036e934a
...@@ -3,44 +3,8 @@ ...@@ -3,44 +3,8 @@
import { createRouter, createWebHashHistory } from "vue-router"; import { createRouter, createWebHashHistory } from "vue-router";
import store from "../store"; import store from "../store";
//写入初始必须有的路由 //写入初始必须有的路由
//或者隐藏式路由,不会表现在菜单上,但是需要存在的路由 //或者隐藏式路由,不会表现在菜单上,但是需要存在的路由
<<<<<<< Updated upstream
const routes = [{
path: "/login",
name: "login",
show: true,
component: () =>
import ("../page/login/index.vue"),
},
{
path: "/register",
name: "register",
show: true,
component: () =>
import ("../page/register/index.vue"),
},
{
path: "/password",
name: "password",
show: true,
component: () =>
import ("../page/password/index.vue"),
},
{
path: "/",
name: "index",
component: () =>
import ("../page/welcom.vue"),
},
{
path: "/404",
show: true,
component: () =>
import ("../page/404.vue"),
},
=======
const routes = [ const routes = [
{ {
path: "/login", path: "/login",
...@@ -64,7 +28,6 @@ const routes = [ ...@@ -64,7 +28,6 @@ const routes = [
show: true, show: true,
component: () => import("../page/404.vue"), component: () => import("../page/404.vue"),
}, },
>>>>>>> Stashed changes
]; ];
//重新创建router //重新创建router
...@@ -79,37 +42,26 @@ const router = newRouterFunc(); ...@@ -79,37 +42,26 @@ const router = newRouterFunc();
function inWhiteList(toPath) { function inWhiteList(toPath) {
//配置白名单 //配置白名单
const whiteList = ['/login'] const whiteList = ["/login"];
const path = whiteList.find((value) => { const path = whiteList.find((value) => {
// 使用正则匹配 // 使用正则匹配
const reg = new RegExp('^' + value) const reg = new RegExp("^" + value);
return reg.test(toPath) return reg.test(toPath);
}) });
return !!path return !!path;
} }
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
<<<<<<< Updated upstream
=======
const userInfo = store.state.userInfo; const userInfo = store.state.userInfo;
//已登录不可跳转登陆页 || to.path == "/" 去除首页跳转判断
if (userInfo && to.path == "/login") {
return next({
path: "/",
});
}
>>>>>>> Stashed changes
const userInfo = store.state.userInfo
//已登录不可跳转登陆页 //已登录不可跳转登陆页
if (userInfo && to.path == '/login') { if (userInfo && to.path == "/login") {
next({ path: from.path }) next({ path: from.path });
} }
// 检查to.path是否存在于免登陆白名单 // 检查to.path是否存在于免登陆白名单
if (inWhiteList(to.path)) { if (inWhiteList(to.path)) {
next() next();
} else { } else {
// 判断是否已经登录,未登录则重定向到首页或其他页面(通过query传参记录原来的路径) // 判断是否已经登录,未登录则重定向到首页或其他页面(通过query传参记录原来的路径)
// 根据配置判断是否跳转第三方登录,跳转第三方登录则不跳login // 根据配置判断是否跳转第三方登录,跳转第三方登录则不跳login
...@@ -119,18 +71,16 @@ router.beforeEach((to, from, next) => { ...@@ -119,18 +71,16 @@ router.beforeEach((to, from, next) => {
// path: '/login', // path: '/login',
// }) // })
// } else { // } else {
// } // }
} }
//判读是否匹配,否则跳转404 //判读是否匹配,否则跳转404
if (to.matched.length !== 0) { if (to.matched.length !== 0) {
next() next();
} else { } else {
return next({ path: '/404' }) return next({ path: "/404" });
} }
}) });
// 在路由完成初始导航时调用,如果有异步操作放置到这里 // 在路由完成初始导航时调用,如果有异步操作放置到这里
// 请求相应的角色和菜单 // 请求相应的角色和菜单
...@@ -138,38 +88,33 @@ router.beforeEach((to, from, next) => { ...@@ -138,38 +88,33 @@ router.beforeEach((to, from, next) => {
// generateRoutes() // generateRoutes()
// }) // })
function addRoute(router, routers) { function addRoute(router, routers) {
routers.forEach(e => { routers.forEach((e) => {
router.addRoute(e) router.addRoute(e);
if (e.children && e.children.length) { if (e.children && e.children.length) {
addRoute(router, e.children) addRoute(router, e.children);
} }
}); });
} }
export function generateRoutes() { export function generateRoutes() {
const _asyncRoutes = store.state.route const _asyncRoutes = store.state.route;
if (_asyncRoutes) { if (_asyncRoutes) {
//动态添加路由 //动态添加路由
addRoute(router, _asyncRoutes) addRoute(router, _asyncRoutes);
} }
router.addRoute({ router.addRoute({
path: '/:pathMatch(.*)', path: "/:pathMatch(.*)",
redirect: '/404' redirect: "/404",
}) });
} }
//新创建一个router替代之前的router,并把matcher方法替换成新的router的matcher //新创建一个router替代之前的router,并把matcher方法替换成新的router的matcher
export function resetRouter() { export function resetRouter() {
const newRouter = newRouterFunc() const newRouter = newRouterFunc();
router.matcher = newRouter.matcher router.matcher = newRouter.matcher;
} }
export default router;
export default router
\ No newline at end of file
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