index.js 927 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. export function SET_ROUTER({ routes, router }) {
  2. router.$plugin = {
  3. addRoutes: (list, options) => {
  4. if (!options) {
  5. options = {};
  6. }
  7. list.map(e => {
  8. if (!e.component) {
  9. let url = e.viewPath;
  10. if (url) {
  11. if (
  12. /^(http[s]?:\/\/)([0-9a-z.]+)(:[0-9]+)?([/0-9a-z.]+)?(\?[0-9a-z&=]+)?(#[0-9-a-z]+)?/i.test(
  13. e.viewPath
  14. )
  15. ) {
  16. e.meta.iframeUrl = e.viewPath;
  17. e.component = () => import(`@/pages/iframe/index.vue`);
  18. } else {
  19. e.component = () => import(`@/${e.viewPath}`);
  20. }
  21. } else {
  22. e.redirect = '/404';
  23. }
  24. }
  25. });
  26. router.addRoutes([
  27. {
  28. path: '/',
  29. component: resolve => require([`@/pages/layout/index.vue`], resolve),
  30. children: [...list, ...routes]
  31. },
  32. {
  33. path: '*',
  34. redirect: '/404'
  35. }
  36. ]);
  37. },
  38. to: url => {
  39. if (router.path != url) {
  40. router.push(url);
  41. }
  42. }
  43. };
  44. }