import Vue from 'vue'; import VueRouter from 'vue-router'; import store from '@/store/index'; Vue.use(VueRouter); const routes = [ // 首页 { path: '/', name: 'index', meta: { title: '首页', isleftarrow: false }, component: () => import('../views/index.vue'), }, // 直播大厅 { path: '/live/index', name: 'live_index', meta: { title: '直播大厅', isleftarrow: false }, component: () => import('../views/live/index.vue'), }, { path: '/live/detail', name: 'live_detail', meta: { title: '直播详情', isleftarrow: true }, component: () => import('../views/live/detail.vue'), }, // 科技超市 { path: '/market/index', name: 'market_index', meta: { title: '科技超市', isleftarrow: false }, component: () => import('../views/market/index.vue'), }, { path: '/market/productDetail', name: 'market_productDetail', meta: { title: '科技超市详情', isleftarrow: true }, component: () => import('../views/market/productDetail.vue'), }, { path: '/market/exportDetail', name: 'market_exportDetail', meta: { title: '专家详情', isleftarrow: true }, component: () => import('../views/market/exportDetail.vue'), }, // 创新服务 { path: '/service/index', name: 'service_index', meta: { title: '创新服务', isleftarrow: false }, component: () => import('../views/service/index.vue'), }, { path: '/service/detail', name: 'service_detail', meta: { title: '创新服务', isleftarrow: true }, component: () => import('../views/service/detail.vue'), }, // 个人中心 { path: '/user/index', name: 'user_index', meta: { title: '个人中心', isleftarrow: false }, component: () => import('../views/user/index.vue'), }, // 用户-基本信息 { path: '/userCenter/user/index', name: 'user_index', meta: { title: '基本信息', isleftarrow: true }, component: () => import('../views/userCenter/user/index.vue'), }, // 用户-我的发布 { path: '/userCenter/myProduct/index', name: 'myProduct_index', meta: { title: '我的发布', isleftarrow: true }, component: () => import('../views/userCenter/myProduct/index.vue'), }, //用户-发布产品 { path: '/userCenter/myProduct/detail', name: 'myProduct_index', meta: { title: '信息管理', isleftarrow: true }, component: () => import('../views/userCenter/myProduct/detail.vue'), }, // 用户-事项管理 { path: '/userCenter/matter/index', name: 'matter_index', meta: { title: '事项管理', isleftarrow: true }, component: () => import('../views/userCenter/matter/index.vue'), }, // 用户-交易完成 { path: '/userCenter/matter/detail', name: 'matter_detail', meta: { title: '交易完成', isleftarrow: true }, component: () => import('../views/userCenter/matter/detail.vue'), }, // 用户-展会管理 { path: '/userCenter/dock/index', name: 'dock_index', meta: { title: '展会管理', isleftarrow: true }, component: () => import('../views/userCenter/dock/index.vue'), }, { path: '/userCenter/dock/detail', name: 'detail', meta: { title: '申请', isleftarrow: true }, component: () => import('../views/userCenter/dock/detail.vue'), }, // 管理用户菜单 // 管理-用户管理 { path: '/adminCenter/user/index', name: 'adminCenter_user_index', meta: { title: '用户管理', isleftarrow: true }, component: () => import('../views/adminCenter/user/index.vue'), }, // 管理-查看用户 { path: '/adminCenter/user/detail', name: 'adminCenter_user_detail', meta: { title: '审核/查看用户', isleftarrow: true }, component: () => import('../views/adminCenter/user/detail.vue'), }, // 管理-展会管理 { path: '/adminCenter/duijiehui/index', name: 'adminCenter_duijiehui_index', meta: { title: '展会管理', isleftarrow: true }, component: () => import('../views/adminCenter/duijiehui/index.vue'), }, // 管理-展会信息管理 { path: '/adminCenter/duijiehui/add', name: 'adminCenter_duijiehui_add', meta: { title: '展会信息管理', isleftarrow: true }, component: () => import('../views/adminCenter/duijiehui/add.vue'), }, // 管理-审核管理 { path: '/adminCenter/enterpriseProduct/index', name: 'adminCenter_enterpriseProduct', meta: { title: '审核管理', isleftarrow: true }, component: () => import('../views/adminCenter/enterpriseProduct/index.vue'), }, // 管理-产品信息管理 { path: '/adminCenter/enterpriseProduct/detail', name: 'adminCenter_enterpriseProduct', meta: { title: '产品信息管理', isleftarrow: true }, component: () => import('../views/adminCenter/enterpriseProduct/detail.vue'), }, // 管理-交易审核管理 { path: '/adminCenter/transaction/index', name: 'adminCenter_transaction', meta: { title: '交易审核管理', isleftarrow: true }, component: () => import('../views/adminCenter/transaction/index.vue'), }, // 管理-交易信息管理 { path: '/adminCenter/transaction/detail', name: 'adminCenter_transaction', meta: { title: '交易信息管理', isleftarrow: true }, component: () => import('../views/adminCenter/transaction/detail.vue'), }, //共用-修改密码 { path: '/updatePwd/index', name: 'updatePwd', meta: { title: '修改密码', isleftarrow: true }, component: () => import('../views/updatePwd/index.vue'), }, // 登录-用户+管理 { path: '/login', name: 'login', meta: { title: '登录', isleftarrow: true }, component: () => import('../views/login.vue'), }, // 绑定 { path: '/bind', name: 'bind', meta: { title: '绑定', isleftarrow: false }, component: () => import('../views/bind.vue'), }, // 展会绑定 { path: '/dockbind', name: 'dockbind', meta: { title: '展会绑定', isleftarrow: false }, component: () => import('../views/dockbind.vue'), }, //关注公众号 { path: '/followbind', name: 'followbind', meta: { title: '关注公众号', isleftarrow: false }, component: () => import('../views/followbind.vue'), }, // 错误 { path: '/error', name: 'error', meta: { title: '绑定授权', isleftarrow: false }, component: () => import('../views/followbind.vue'), }, ]; const router = new VueRouter({ mode: 'history', base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROUTER, routes, }); router.beforeEach(async (to, form, next) => { if (to.name == 'user_index') { let res = await store.dispatch('login/toGetUser'); if (res && res.uid) { next(); } else { next({ name: 'login' }); } } else { let res = await store.dispatch('login/toGetUser'); next(); } }); const originalPush = VueRouter.prototype.push; VueRouter.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); }; export default router;