router.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import Vue from 'vue';
  2. import Router from 'uni-simple-router';
  3. Vue.use(Router)
  4. import utils from '../utils/common.js'
  5. //初始化
  6. const router = new Router({
  7. routes:ROUTES //路由表
  8. });
  9. const filters = ['/pages/auth/login','/pages/common/launch']
  10. //进入的路由 要出去的路由
  11. router.beforeEach((to, from, next) => {
  12. console.log("路由进入")
  13. console.log(to)
  14. let index = filters.indexOf(to.path);
  15. //过滤
  16. console.log(index)
  17. if (index > -1) {
  18. next();
  19. return;
  20. }
  21. var data=utils.isLogin();
  22. console.log(data)
  23. if(utils.isLogin()){
  24. console.log("ok")
  25. next();
  26. }
  27. else{
  28. // 条件编译判断平台,设置不同登录页路径
  29. let loginPage = '';
  30. // #ifdef H5
  31. loginPage = '/pages/auth/login';
  32. // #endif
  33. // #ifdef MP-WEIXIN
  34. loginPage = '/pages/auth/wxlogin';
  35. // #endif
  36. next({path: loginPage});
  37. }
  38. //判断是否校验路由
  39. // if (to.meta.isAure) {
  40. // let name = sessionStorage.getItem('username');
  41. // //有状态,并且存在sessionStorage,则next,否则返回登陆页面
  42. // if (name) {
  43. // next();
  44. // } else {
  45. // next({path: "/login",query:{redirect:to.name}});
  46. // }
  47. // } else {
  48. // next();
  49. // }
  50. });
  51. export default router;