index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. if(process.car.NODE_ENV=='dev'||process.car.NODE_ENV=='test'){
  15. uni.setNavigationBarTitle({
  16. title:process.car.ProjectName+'('+process.car.NODE_ENV+')',
  17. })
  18. }
  19. })
  20. uniCrazyRouter['on' + 'Error']((to, from) => {
  21. // 逻辑代码
  22. console.log("Error+start")
  23. console.log(to)
  24. console.log(from)
  25. console.log("Error+end")
  26. })
  27. import Router from './bobo-router'
  28. Vue.use(Router)
  29. // 路由配置 页面中全部使用this.$Router来操作路由,以实现路由的全局管理
  30. const router = new Router()
  31. // 路由全局拦截器 在这里处理登录、授权等相关操作
  32. router.beforeEach(function(to, from, next) {
  33. console.log('前置守卫')
  34. routerBeforeEach(to, from, next);
  35. })
  36. function routerBeforeEach(to, from, next) {
  37. next();
  38. }
  39. // 路由后置拦截器
  40. router.afterEach(function(to, from) {
  41. console.log('后置守卫')
  42. })
  43. // 路由跳转出错处理
  44. router.onError(function(e) {
  45. console.log('错误:', e.message || '路由跳转失败')
  46. })
  47. export default router