/* * @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;