index.js 694 B

12345678910111213141516171819202122232425262728293031
  1. import modules from './modules'
  2. import Vue from 'vue'
  3. import Router from '@/plugin/uni-simple-router/index.js'
  4. import {ACCESS_TOKEN} from '@/common/util/constants.js'
  5. Vue.use(Router)
  6. //初始化
  7. const router = new Router({
  8. encodeURI:true,
  9. routes: [...modules]//路由表
  10. });
  11. const whiteList = ['/pages/login/login']
  12. //全局路由前置守卫
  13. router.beforeEach((to, from, next) => {
  14. let token=uni.getStorageSync(ACCESS_TOKEN);
  15. if(token){
  16. next()
  17. }else{
  18. if (whiteList.indexOf(to.path) !== -1) {
  19. next()
  20. }else{
  21. next({ path: '/pages/login/login'})
  22. }
  23. }
  24. })
  25. // 全局路由后置守卫
  26. router.afterEach((to, from) => {
  27. console.log("afterEach")
  28. })
  29. export default router;