import Vue from 'vue';
|
import Router, {Route} from 'vue-router';
|
import dashboardrouter from './dashboard.router';
|
import initialization from "@/route/initialization";
|
|
import listrouter from './list.router';
|
import formrouter from './form.router';
|
import detailrouter from './detail.router';
|
import store from '@/store/store';
|
|
import passportrouter from './passport.router';
|
|
|
// 合并的路由组件
|
import sensors from './sensors.router';
|
import devices from './devices.router';
|
import cache from './cache.router'
|
import usersMange from './usersMange.router'
|
|
|
import MainLayout from '@/layout/main/MainLayout.vue';
|
import system from './system.router';
|
import usermanage from './usermanage.router'
|
import systemset from './systemSet.router'
|
import Analysis from '@/views/dashboard/Analysis.vue'
|
|
Vue.use(Router);
|
|
// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
|
// const originalPush = Router.prototype.push
|
// Router.prototype.push = function push (location, onResolve, onReject) {
|
// if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
|
// return originalPush.call(this, location).catch(err => err)
|
// }
|
|
const router = new Router({
|
base: '/ams',
|
mode: 'history',
|
routes: [
|
dashboardrouter,
|
passportrouter,
|
system
|
],
|
});
|
|
|
/**
|
* 设置全局路由守卫
|
*/
|
router.beforeResolve((to: Route, from: Route, next: any) => {
|
const state: any = store.state;
|
const user: any = state.user;
|
|
// 路由信息设置了需要守卫,跳转路由时需要先登录
|
|
if (to.meta && to.meta.routerGuard) {
|
// 需要路由守护
|
if (sessionStorage.getItem('token') === null) {
|
next({
|
name: '/passport/login', query: {
|
redirect: to.path,
|
}
|
});
|
return;
|
}
|
}
|
|
|
next();
|
});
|
|
router.beforeEach((to, from, next) => {
|
next();
|
});
|
|
router.afterEach((to: any, from: any) => {
|
const tabInfo: any = {
|
name: to.name,
|
closable: true,
|
path: to.name,
|
title: to.meta.title,
|
activeName: from.name,
|
i18n: to.meta.i18n || null,
|
};
|
|
// 设置复用tab
|
store.dispatch('reuseTab/add', tabInfo);
|
// 设置标题
|
store.commit('app/changeTitle', {
|
title: tabInfo.title,
|
i18n: tabInfo.i18n,
|
},
|
);
|
});
|
|
// 解决导航栏中的vue-router在3.0版本以上重复点菜单报错问题
|
const originalPush = Router.prototype.push
|
Router.prototype.push = function push(location: any) {
|
return originalPush.call(this, location).catch((err: any) => err)
|
}
|
|
export default router;
|