index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // import carhelp from '@/utils/mixin.js'
  2. import Vue from 'vue'
  3. // 先运行yarn 初始化
  4. import uniCrazyRouter from "uni-crazy-router";
  5. Vue.use(uniCrazyRouter)
  6. //** 有bug, 第一次直接敲链接访问, 是访问bobo-router 前置守卫
  7. //** 后续操作,访问的是 uniCrazyRouter的前置守卫
  8. uniCrazyRouter.beforeEach(async (to, from, next) => {
  9. routerBeforeEach(to, from, next);
  10. })
  11. uniCrazyRouter.afterEach((to, from) => {
  12. // 逻辑代码
  13. console.log("afterEach")
  14. var ProjectName=process.car.ProjectName;
  15. if(process.car.NODE_ENV=='dev'||process.car.NODE_ENV=='test'){
  16. ProjectName+='('+process.car.NODE_ENV+')';
  17. }
  18. uni.setNavigationBarTitle({
  19. title:ProjectName
  20. })
  21. })
  22. uniCrazyRouter['on' + 'Error']((to, from) => {
  23. // 逻辑代码
  24. console.log("Error+start")
  25. console.log(to)
  26. console.log(from)
  27. console.log("Error+end")
  28. })
  29. import Router from './bobo-router'
  30. import carhelp from '@/apis/utils/mixin.js'
  31. Vue.use(Router)
  32. // 路由配置 页面中全部使用this.$Router来操作路由,以实现路由的全局管理
  33. const router = new Router()
  34. // 路由全局拦截器 在这里处理登录、授权等相关操作
  35. router.beforeEach(function(to, from, next) {
  36. routerBeforeEach(to, from, next);
  37. })
  38. function routerBeforeEach(to, from, next) {
  39. next();
  40. }
  41. // 路由后置拦截器
  42. router.afterEach(function(to, from) {
  43. console.log('后置守卫')
  44. })
  45. // 路由跳转出错处理
  46. router.onError(function(e) {
  47. console.log('错误:', e.message || '路由跳转失败')
  48. })
  49. export default router