// router.js import { RouterMount, createRouter } from 'uni-simple-router'; import store from '@/store/index.js' // console.log(ROUTES); const router = createRouter({ platform: process.env.VUE_APP_PLATFORM, //H5跳转路由锁 routerErrorEach: (error, router) => { if (error.type === 3) { /* error.type 0 表示 next(false) 1 表示 next(unknownType) 2 表示加锁状态,禁止跳转 3 表示在获取页面栈的时候,页面栈不够level获取 */ router.$lockStatus = false; } }, //小程序跳转路由锁 applet: { animationDuration: 300 //默认 300ms v2.0.6+ }, routes: [...ROUTES] }); //全局路由前置守卫 router.beforeEach((to, from, next) => { // next(); if (store.getters.token) { next(); } else { if ( // 这些页面不需要验证登录 to.path == '/pages/login/index' || '/pages/login/indexs' || '/pages/index/index' ) { next(); } else { next('/pages/login/index'); } } }); // 全局路由后置守卫 router.afterEach((to, from) => { // console.log('跳转结束') }) export { router, RouterMount }