| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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/Main.vue'),
- meta: {
- title: "首页",
- clmid: "1",
- }
- },{
- path: '/rank',
- name: 'Rank',
- component: () => import('@/views/Rank.vue'),
- meta: {
- title: "排名",
- clmid: "2",
- }
- },{
- path: '/pk',
- name: 'pk',
- component: () => import('@/views/pk.vue'),
- meta: {
- title: "pk",
- clmid: "3",
- }
- },
- ]
- }, {
- 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
|