| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import Vue from 'vue'
- import VueRouter from 'vue-router'
- // 路由3+版本的异常处理
- const originalPush = VueRouter.prototype.push
- VueRouter.prototype.push = function push(location) {
- return originalPush.call(this, location).catch(err => err)
- }
- const originalReplace = VueRouter.prototype.replace;
- VueRouter.prototype.replace = function replace(location) {
- return originalReplace.call(this, location).catch(err => err);
- }
- // 公共页面
- import main from '@views/main'
- import error404 from '@views/404'
- // 子路由
- import yRouter from '@router/ylf';
- import lRouter from '@router/lzx';
- import zRouter from '@router/zm';
- Vue.use(VueRouter)
- const routes = [
- {
- path: '/',
- meta: {
- requireAuth: true, // 添加该字段,表示进入这个路由是需要登录的
- },
- component: main,
- children:[
- { // 首页
- path:'/',
- component: r => require.ensure([], () => r(require('@views/index/index')), 'indexM')
- },
- ...yRouter,
- ...lRouter,
- ...zRouter
- ]
- },
- {
- path: '/404', // 页面不存在的情况下会跳到404页面
- meta: {
- requireAuth: true, // 添加该字段,表示进入这个路由是需要登录的 /进路由勾子函数beforeEach
- },
- name: 'error404',
- component: error404,
- },
- // { // 健康评价报告 - 临时 /部署单页面
- // path:'/healthAssessmentDetailed2',
- // component: r => require.ensure([], () => r(require('@views/healthManagement/healthAssessmentDetailed')), 'healthManagement')
- // },
- ]
- const router = new VueRouter({
- mode: 'history',
- base: '/sis/', // 部署单页面 404 history 带井号解决(去掉history 放web-inf)
- routes
- })
- /**
- * 路由的钩子函数,处理是否登录的判断
- * **/
- router.beforeEach((to, from, next) => {
- // 路由地址不存在的处理办法
- if (to.matched.length === 0) { // 如果未匹配到路由
- // sessionStorage.removeItem("btrh_sxsd_locationHref");
- next('/404') // 如果上级也未匹配到路由则跳转登录页面,如果上级能匹配到则转上级路由
- }
- if (to.matched.some(r => r.meta.requireAuth)) {
- let userinfo = JSON.parse(sessionStorage.getItem("btrh_sxsd_userinfo"));
- userinfo = "";
- if(userinfo !== null){
- // if(to.path !== "/"){
- // // 判断当前菜单是否有权限打开,如果无权限,自动退出
- // routerCheck(userinfo.roleId, to.path, next);
- // }else{
- // next();
- // }
- next();
- return;
- }
- next("/login");
- } else {
- next();
- }
- })
- export default router
|