index.js 1.7 KB

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