// import carhelp from '@/utils/mixin.js' import Vue from 'vue' // 先运行yarn 初始化 import uniCrazyRouter from "uni-crazy-router"; Vue.use(uniCrazyRouter) //** 有bug, 第一次直接敲链接访问, 是访问bobo-router 前置守卫 //** 后续操作,访问的是 uniCrazyRouter的前置守卫 uniCrazyRouter.beforeEach(async (to, from, next) => { routerBeforeEach(to, from, next); }) uniCrazyRouter.afterEach((to, from) => { // 逻辑代码 console.log("afterEach") var ProjectName=process.car.ProjectName; if(process.car.NODE_ENV=='dev'||process.car.NODE_ENV=='test'){ ProjectName+='('+process.car.NODE_ENV+')'; } uni.setNavigationBarTitle({ title:ProjectName }) }) uniCrazyRouter['on' + 'Error']((to, from) => { // 逻辑代码 console.log("Error+start") console.log(to) console.log(from) console.log("Error+end") }) import Router from './bobo-router' import carhelp from '@/apis/utils/mixin.js' Vue.use(Router) // 路由配置 页面中全部使用this.$Router来操作路由,以实现路由的全局管理 const router = new Router() // 路由全局拦截器 在这里处理登录、授权等相关操作 router.beforeEach(function(to, from, next) { if(from.page.indexOf('/pages/businessHall/')==0){ carhelp.setRole("businessHall") } if(from.page.indexOf('/pages/energyCenter/')==0){ carhelp.setRole("energyCenter") } routerBeforeEach(to, from, next); }) function routerBeforeEach(to, from, next) { next(); } // 路由后置拦截器 router.afterEach(function(to, from) { console.log('后置守卫') }) // 路由跳转出错处理 router.onError(function(e) { console.log('错误:', e.message || '路由跳转失败') }) export default router