router.js 881 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import Vue from 'vue'
  2. import Router from 'uni-simple-router'
  3. Vue.use(Router)
  4. //初始化
  5. const router = new Router({
  6. APP: {
  7. animation: {
  8. animationType: 'pop-in',
  9. animationDuration: 300
  10. }
  11. },
  12. encodeURI: true,
  13. routes: ROUTES //路由表
  14. });
  15. //全局路由前置守卫
  16. router.beforeEach((to, from, next) => {
  17. console.log('to',to)
  18. console.log('----willGo----',to.path)
  19. // 有两个个判断条件,一个是token,还有一个路由元信息
  20. if(to.path!='/pages/login/login'){
  21. uni.setStorageSync('fromLogin',{path: to.path,query: to.query})
  22. }
  23. if (to.meta && to.meta.auth) {
  24. console.log('我要登录');
  25. // next('/pages/login/login');
  26. next();
  27. } else {
  28. console.log('正常跳转页面');
  29. next();
  30. }
  31. })
  32. // 全局路由后置守卫
  33. router.afterEach((to, from) => {
  34. })
  35. export default router;