router.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {
  2. RouterMount,
  3. createRouter,
  4. runtimeQuit
  5. } from 'uni-simple-router';
  6. //配置白名单
  7. let WHiTE_LIST=['login']
  8. let first = null;
  9. const router = createRouter({
  10. platform: process.env.VUE_APP_PLATFORM,
  11. APP:{
  12. animation:{
  13. animationType:'slide-in-top',
  14. animationDuration:300
  15. }
  16. },
  17. routerBeforeEach:(to, from, next) => {
  18. if (WHiTE_LIST.includes(to.name)) {
  19. next();
  20. }else{
  21. //拦截未登录页面并跳转到登录页面
  22. let phone =uni.getStorageSync("phone")
  23. console.log(phone);
  24. if (phone) {
  25. next();
  26. }else{
  27. next({
  28. name: 'login',
  29. params: { fullPath: to.fullPath },
  30. NAVTYPE: 'replaceAll'
  31. });
  32. }
  33. }
  34. },
  35. routerAfterEach:(to, from) => {
  36. console.log('--------routerAfterEach----')
  37. },
  38. routerErrorEach:({type,msg})=>{
  39. console.log({type,msg})
  40. // #ifdef APP-PLUS
  41. if(type===3){
  42. router.$lockStatus=false;
  43. runtimeQuit();
  44. }
  45. // #endif
  46. },
  47. routes: [
  48. ...ROUTES,
  49. {
  50. path: '*',
  51. redirect:(to)=>{
  52. return {name:'404'}
  53. }
  54. },
  55. ]
  56. });
  57. let count=0;
  58. router.beforeEach((to, from, next) => {
  59. // if(count==0){
  60. // next({
  61. // path:'/pages/login/login',
  62. // NAVTYPE:'replaceAll'
  63. // })
  64. // }else{
  65. // next();
  66. // }
  67. next();
  68. count++;
  69. });
  70. router.afterEach((to, from, next) => {
  71. console.log('afterEach---跳转结束')
  72. });
  73. export {
  74. router,
  75. RouterMount
  76. }