import Vue from 'vue'; import VueRouter from 'vue-router'; import store from '@/store/index'; const originalPush = VueRouter.prototype.push; VueRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err); }; const jwt = require('jsonwebtoken'); const list = [ { path: '/market/list', name: 'market_list', meta: { title: '科技超市' }, component: () => import('../views/market/list.vue'), }, { path: '/techolchat/list', name: 'techolchat_list', meta: { title: '技术交流' }, component: () => import('../views/techolchat/list.vue'), }, { path: '/news/list', name: 'news_list', meta: { title: '新闻资讯' }, component: () => import('../views/news/list.vue'), }, ]; const admin = [ { path: '/admin/live/science', name: 'admin_live_science', meta: { title: '科技频道管理中心' }, component: () => import('../views/admin/live/science.vue'), }, { path: '/admin/live/train', name: 'admin_live_train', meta: { title: '培训问诊管理中心' }, component: () => import('../views/admin/live/train.vue'), }, { path: '/admin/live/achieve', name: 'admin_live_achieve', meta: { title: '科技成果管理中心' }, component: () => import('../views/admin/live/achieve.vue'), }, ]; Vue.use(VueRouter); const live = [ { path: '/', name: 'index', meta: { title: '网站首页' }, component: () => import('../views/index.vue'), }, { path: '/login', name: 'login', meta: { title: '登录' }, component: () => import('../views/login.vue'), }, { path: '/register', name: 'register', meta: { title: '注册账号' }, component: () => import('../views/register.vue'), }, { path: '/agreement', name: 'agreement', meta: { title: '用户注册协议' }, component: () => import('../views/agreement.vue'), }, { path: '/channelLive/index', name: 'channelLive_index', meta: { title: '直播大厅-科技频道', subSite: true }, component: () => import('../views/channelLive/index.vue'), }, { path: '/trainLive/index', name: 'trainLive_index', meta: { title: '直播大厅-培训问诊', subSite: true }, component: () => import('../views/trainLive/index.vue'), }, { path: '/personalLive/index', name: 'personalLive_index', meta: { title: '直播大厅-人才对接', subSite: true }, component: () => import('../views/personalLive/index.vue'), }, { path: '/achieveLive/before', name: 'personalLive_before', meta: { title: '直播大厅-展会活动页', subSite: true }, component: () => import('../views/achieveLive/before.vue'), }, { path: '/achieveLive/detail', name: 'personalLive_detail', meta: { title: '直播大厅-展会详情', subSite: true }, component: () => import('../views/achieveLive/detail.vue'), }, // { // path: '/achieveLive/expert/index', // name: 'achieveLive_expert', // meta: { title: '直播大厅-参展专家', subSite: true }, // component: () => import('../views/achieveLive/expert/index.vue'), // }, // { // path: '/achieveLive/expert/detail', // name: 'achieveLive_detail', // meta: { title: '直播大厅-对接专家', subSite: true }, // component: () => import('../views/achieveLive/expert/detail.vue'), // }, // { // path: '/achieveLive/product/index', // name: 'achieveLive_product', // meta: { title: '直播大厅-参展项目', subSite: true }, // component: () => import('../views/achieveLive/product/index.vue'), // }, // { // path: '/achieveLive/product/detail', // name: 'achieveLive_detail', // meta: { title: '直播大厅-对接项目', subSite: true }, // component: () => import('../views/achieveLive/product/detail.vue'), // }, { path: '/achieveLive/news/detail', name: 'achieveLive_news_detail', meta: { title: '直播大厅-嘉宾访谈,项目路演', subSite: true }, component: () => import('../views/achieveLive/news/detail.vue'), }, { path: '/website', name: 'website', component: () => import('../views/website.vue'), children: [ // 新闻资讯 { path: '/news/index', name: 'news_index', meta: { title: '新闻资讯', subSite: true }, component: () => import('../views/news/index.vue'), }, // 科技超市 { path: '/market/index', name: 'market_index', meta: { title: '科技超市', subSite: true }, component: () => import('../views/market/index.vue'), }, ...list, // 直播大厅 { path: '/live/index', name: 'live_index', meta: { title: '直播大厅', subSite: true }, component: () => import('../views/live/index.vue'), }, { path: '/achieveLive/apply', name: 'achieveLive_apply', meta: { title: '直播大厅-申请参展', subSite: true }, component: () => import('../views/achieveLive/apply.vue'), }, // 数据动态 { path: '/dynamic/index', name: 'dynamic_index', meta: { title: '数据动态', subSite: true }, component: () => import('../views/dynamic/index.vue'), }, // 技术交流 { path: '/techolchat/index', name: 'techolchat_index', meta: { title: '技术交流', subSite: true }, component: () => import('../views/techolchat/index.vue'), }, { path: '/techolchat/product', name: 'techolchat_product', meta: { title: '信息发布', subSite: true }, component: () => import('../views/techolchat/product.vue'), }, { path: '/userCenter', name: 'userCenter', meta: { title: '管理中心' }, component: () => import('../views/userCenter/index.vue'), }, ...admin, // 问卷调查 { path: '/questionnaire/index', name: 'questionnaire', meta: { title: '问卷调查' }, component: () => import('../views/questionnaire/index.vue'), }, // 答问卷调查 { path: '/questionnaire/answer', name: 'questionnaire', meta: { title: '完成问卷调查' }, component: () => import('../views/questionnaire/detail.vue'), }, // 科技创新能力评价 { path: '/newteck/index', name: 'newteck', meta: { title: '科技创新能力评价' }, component: () => import('../views/newTeck/index.vue'), }, ], }, ]; const routes = [...live]; const router = new VueRouter({ mode: 'history', base: process.env.VUE_APP_ROUTER, routes, }); router.beforeEach((to, from, next) => { document.title = `${to.meta.title} `; const token = localStorage.getItem('token'); if (to.path == '/userCenter') { if (!token) { next('/login'); } else { let user = jwt.decode(token); user.type = '4'; store.commit('setUser', user, { root: true }); next(); } } else { let user = jwt.decode(token); store.commit('setUser', user, { root: true }); next(); } }); export default router;