router.js 2.2 KB

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