router.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Vue from 'vue';
  2. import VueRouter from 'vue-router';
  3. import _ from 'lodash';
  4. const CardIndex = () => import('./components/CardIndex/CardIndex.vue');
  5. const Search = () => import('./components/CardIndex/Search/Search.vue');
  6. const Card = () => import('./components/CardIndex/Card/Card.vue');
  7. const Book = () => import('./components/CardIndex/Book/Book.vue');
  8. const History = () => import('./components/CardIndex/History/History.vue');
  9. //немедленная загрузка
  10. //import Reader from './components/Reader/Reader.vue';
  11. const Reader = () => import('./components/Reader/Reader.vue');
  12. const ExternalLibs = () => import('./components/ExternalLibs/ExternalLibs.vue');
  13. const Income = () => import('./components/Income/Income.vue');
  14. const Sources = () => import('./components/Sources/Sources.vue');
  15. const Settings = () => import('./components/Settings/Settings.vue');
  16. const Help = () => import('./components/Help/Help.vue');
  17. //const NotFound404 = () => import('./components/NotFound404/NotFound404.vue');
  18. const myRoutes = [
  19. ['/', null, null, '/cardindex'],
  20. ['/cardindex', CardIndex],
  21. ['/cardindex~search', Search],
  22. ['/cardindex~card', Card],
  23. ['/cardindex~card/:authorId', Card],
  24. ['/cardindex~book', Book],
  25. ['/cardindex~book/:bookId', Book],
  26. ['/cardindex~history', History],
  27. ['/reader', Reader],
  28. ['/external-libs', ExternalLibs],
  29. ['/income', Income],
  30. ['/sources', Sources],
  31. ['/settings', Settings],
  32. ['/help', Help],
  33. ['*', null, null, '/cardindex'],
  34. ];
  35. let routes = {};
  36. for (let route of myRoutes) {
  37. const [path, component, name, redirect] = route;
  38. let cleanRoute = _.pickBy({path, component, name, redirect}, _.identity);
  39. let parts = cleanRoute.path.split('~');
  40. let f = routes;
  41. for (let part of parts) {
  42. const curRoute = _.assign({}, cleanRoute, { path: part });
  43. if (!f.children)
  44. f.children = [];
  45. let r = f.children;
  46. f = _.find(r, {path: part});
  47. if (!f) {
  48. r.push(curRoute);
  49. f = curRoute;
  50. }
  51. }
  52. }
  53. routes = routes.children;
  54. Vue.use(VueRouter);
  55. export default new VueRouter({
  56. routes
  57. });