router.js 746 B

12345678910111213141516171819202122232425262728293031
  1. import {
  2. createRouter,
  3. } from '@gowiny/uni-router'
  4. import PAGE_DATA from '@/pages.json';
  5. const router = createRouter({
  6. pageData: PAGE_DATA
  7. })
  8. router.beforeEach((to, from) => {
  9. uni.$grace.showLoading("加载中...");
  10. })
  11. router.afterEach((to, from) => {
  12. uni.hideLoading();
  13. const oldPath = uni.getStorageSync('oldPath');
  14. const path = uni.getStorageSync('path');
  15. if (oldPath != null) {
  16. uni.setStorageSync('oldPath', path);
  17. uni.setStorageSync('path', to.fullPath);
  18. } else {
  19. uni.setStorageSync('oldPath', to.fullPath);
  20. uni.setStorageSync('path', to.fullPath);
  21. }
  22. // return new Promise((success, fail) => {
  23. // setTimeout(function() {
  24. // console.log('afterEach 2 end') success(true)
  25. // }, 1000)
  26. // })
  27. })
  28. export default router;