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