| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import Vue from 'vue'
- import VueRouter from 'vue-router'
- // 加载条
- import NProgress from 'nprogress'
- import 'nprogress/nprogress.css'
- import VueAMap from 'vue-amap';
- Vue.use(VueRouter);
- // Vue.use(VueAMap);
- // VueAMap.initAMapApiLoader({
- // key: 'your amap key',
- // plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
- // // 默认高德 sdk 版本为 1.4.4
- // v: '1.4.4'
- // });
- const routes = [
- {
- path: '/',
- component: () => import( '../views/Index.vue'),
- children: [
- {
- path: '/',
- name: 'Main',
- component: () => import('@/views/Wait.vue'),
- meta: {
- title: "等待",
- clmid: "1",
- }
- },{
- path: '/main',
- name: 'Main',
- component: () => import('@/views/Main.vue'),
- meta: {
- title: "团课",
- clmid: "1",
- }
- },{
- path: '/rank',
- name: 'Rank',
- component: () => import('@/views/Rank.vue'),
- meta: {
- title: "排名",
- clmid: "2",
- }
- },{
- path: '/wait',
- name: 'Wait',
- component: () => import('@/views/Wait.vue'),
- meta: {
- title: "等待",
- clmid: "2",
- }
- },{
- path: '/pk',
- name: 'pk',
- component: () => import('@/views/pk.vue'),
- meta: {
- title: "pk",
- clmid: "3",
- }
- },{
- path: '/gropePk',
- name: 'gropePk',
- component: () => import('@/views/gropePk.vue'),
- meta: {
- title: "gropePk",
- clmid: "4",
- }
- },{
- path: '/2pkRank',
- name: '2pkRank',
- component: () => import('@/views/2pkRank.vue'),
- meta: {
- title: "2pkRank",
- clmid: "5",
- }
- },{
- path: '/3pk',
- name: '3pk',
- component: () => import('@/views/3pk.vue'),
- meta: {
- title: "3pk",
- clmid: "6",
- }
- },{
- path: '/test',
- name: 'test',
- component: () => import('@/views/test.vue'),
- meta: {
- title: "test",
- clmid: "999",
- }
- },
- ]
- }, {
- path: '*',
- name: '404',
- component: () => import( '../views/404.vue')
- },
- ]
- const originalPush = VueRouter.prototype.push;
- VueRouter.prototype.push = function push(location) {
- return originalPush.call(this, location).catch(err => err)
- };
- const router = new VueRouter({
- // mode: 'history',
- mode: 'hash',
- base: process.env.BASE_URL,
- routes
- });
- // 路由守卫
- router.beforeEach((to,from,next)=>{
- NProgress.start();
- const isLogin = localStorage.token? true : false;
- if(to.path == '/login' || to.path == '/register'){//'login'和'register'相当于是路由白名单
- next();
- }else{
- //如果token存在,就正常跳转,如果不存在,则说明未登陆,则跳转到'login'
- // isLogin? next() : next("/login");
- next();
- }
- });
- router.afterEach(() => {
- NProgress.done()
- });
- export default router
|