码迷,mamicode.com
首页 > Web开发 > 详细

router--- index.js

时间:2020-04-28 23:18:03      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:rect   amp   outer   config   router   spro   export   mode   default   

import Vue from ‘vue‘;
import Router from ‘vue-router‘;
import store from ‘../store‘;
import Api from ‘../lib/api/api‘;

import Homes from ‘../views/homes/homes‘;
import Index from ‘../views/homes/index‘;


Vue.use(Router);

let router = new Router({
// mode: ‘history‘,
routes: [
{ path: ‘/‘, redirect: ‘/login‘},
{
path: ‘/home‘,
name: ‘home‘,
component: Homes,
children: [
{ path: ‘/‘, name: ‘home‘, component: Index2},
{ path: ‘/index‘, name: ‘index‘, component: Index},
]
},
{ path: ‘/bet/:sign‘, name: ‘bet‘, component: Bet},
{ path: ‘*‘, redirect: ‘/home‘}
]
});



router.beforeEach((to, from, next) => {


// 处理路由切换时 切换效果
if(document.documentElement[‘scrollTop‘]) {
document.documentElement.scrollTop = 0;
} else {
document.body.scrollTop = 0;
}

// 跳转路由 取消上个路由的请求
if(store.state[‘axiosPromiseCancel‘].length > 0) {
store.state[‘axiosPromiseCancel‘].forEach(e => {
e && e.f()
});
}
store.state[‘axiosPromiseCancel‘] = [];

if(!store.state.baseConfig.banner) {
Api.baseConfig().then(response => {
if (response.success) {
store.state.baseConfig = response.data;
}
})
}
// 是否加密
// Api.isCryptData().then( response => {
// if (response[‘success‘]) {
// window.isCryptData = response[‘data‘];
//
// }
// });
next();

});

export default router;

router--- index.js

标签:rect   amp   outer   config   router   spro   export   mode   default   

原文地址:https://www.cnblogs.com/zhaofeis/p/12797954.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!