// 整合路由配置、路由拦截;(可扩展页面进度条)
|
|
import Vue from "vue";
|
import VueRouter from "vue-router";
|
// import myConfig from "@/assets/js/config";
|
|
// 路由数据
|
import routes from "./routes";
|
|
Vue.use(VueRouter);
|
|
const router = new VueRouter({
|
routes
|
});
|
|
/**
|
* 路由拦截
|
* 权限验证
|
*/
|
// router.beforeEach((to, from, next) => {
|
// // 验证路由是否需要有登录验证
|
// if (to.matched.some(r => r.meta.requiresAuth)) {
|
// // 这里暂时将localStorage里是否存有token作为验证是否登录的条件
|
// // 请根据自身业务需要修改
|
// const token = localStorage.getItem(myConfig.tokenName);
|
// if (token && token !== "undefined") {
|
// next();
|
// } else {
|
// // 验证不通过跳转到登录界面,将当前预计打开的页面完整地址传递至登录页面,登录后继续跳转
|
// next({
|
// name: "login",
|
// query: {
|
// redirect: to.fullPath
|
// }
|
// });
|
// }
|
// } else {
|
// // 不需要身份校验 直接通过
|
// next();
|
// }
|
// });
|
|
export default router;
|