index.js 1.5 KB

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