zhaoxiaoqiang
2022-11-10 afd7bc9b1512074c5e09927852ae91b6a609827c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * @Author: 小明丶
 * @Date: 2019-08-19 15:23:17
 * @LastEditors: zxq
 * @LastEditTime: 2022-11-10 10:01:08
 * @Description:
 */
import Vue from "vue";
import VueRouter from 'vue-router';
import routes from './routes';
import Store from '@/store';
Vue.use(VueRouter);
 
let router =  new VueRouter({
    mode:"hash", //history
    routes,
    scrollBehavior (to, from, savedPosition) {
        return {
            x:0,
            y:0
        }
    },
})
 
// 全局前置守卫:页面跳转前拦截
router.beforeEach((to, from, next) => {
    if(to.meta.isLogin){
        next()
    }else{
        // 需要登录的页面
        if(Store.state.sessionId){
            next()
        }else{
            next('/')
        }
    }
})
 
 
//全局后置守卫:页面跳转后执行
router.afterEach((to, from) => {
 
})
 
export default router;