123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- import Vue from 'vue';
- import VueRouter from 'vue-router';
- import store from '@/store/index';
- const jwt = require('jsonwebtoken');
- Vue.use(VueRouter);
- const admin = [
- {
- path: '/admin/index',
- meta: { title: '统计报表', isleftarrow: false },
- component: () => import('../views/adminCenter/index.vue'),
- },
- {
- path: '/adminRefute',
- meta: { title: '文章辟谣', isleftarrow: false },
- component: () => import('../views/adminCenter/adminRefute.vue'),
- },
- {
- path: '/adminRefute/edit',
- meta: { title: '文章辟谣', isleftarrow: false },
- component: () => import('../views/adminCenter/refute/edit.vue'),
- },
- {
- path: '/adminCommunity',
- meta: { title: '社区话题', isleftarrow: false },
- component: () => import('../views/adminCenter/adminCommunity.vue'),
- },
- {
- path: '/adminCommunity/edit',
- meta: { title: '社区话题', isleftarrow: false },
- component: () => import('../views/adminCenter/topic/edit.vue'),
- },
- {
- path: '/adminServe',
- meta: { title: '咨询服务', isleftarrow: false },
- component: () => import('../views/adminCenter/adminServe.vue'),
- },
- {
- path: '/adminServe/edit',
- meta: { title: '咨询服务', isleftarrow: false },
- component: () => import('../views/adminCenter/serve/edit.vue'),
- },
- ];
- const routes = [
- {
- path: '/',
- meta: { title: '系统首页', isleftarrow: false },
- component: () => import('../views/index.vue'),
- },
- {
- path: '/login',
- meta: { title: '管理登陆', isleftarrow: false },
- component: () => import('../views/login.vue'),
- },
- // 文章辟谣
- {
- path: '/refute/index',
- meta: { title: '文章辟谣', isleftarrow: false },
- component: () => import('../views/refute/index.vue'),
- },
- {
- path: '/refute/detail',
- meta: { title: '文章正文', isleftarrow: false },
- component: () => import('../views/refute/detail.vue'),
- },
- // 社区话题
- {
- path: '/community/index',
- meta: { title: '社区话题', isleftarrow: false },
- component: () => import('../views/community/index.vue'),
- },
- {
- path: '/community/detail',
- meta: { title: '话题正文', isleftarrow: false },
- component: () => import('../views/community/detail.vue'),
- },
- // 咨询服务
- {
- path: '/service/index',
- meta: { title: '咨询服务', isleftarrow: false },
- component: () => import('../views/service/index.vue'),
- },
- {
- path: '/service/detail',
- meta: { title: '文章正文', isleftarrow: false },
- component: () => import('../views/service/detail.vue'),
- },
- // 引用管理员
- ...admin,
- ];
- const router = new VueRouter({
- mode: 'history',
- base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROUTER,
- routes,
- });
- router.beforeEach(async (to, form, next) => {
- next();
- // if (to.name == 'account_user') {
- // let res = await store.dispatch('login/toGetUser');
- // if (res && res.uid) {
- // next();
- // } else {
- // let key = sessionStorage.getItem('token');
- // let user = jwt.decode(key);
- // if (user && user.uid) {
- // store.commit('setUser', user, { root: true });
- // 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;
|