router.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. const Reader = () => import('./components/Reader/Reader.vue');
  10. //немедленная загрузка
  11. //import Reader from './components/Reader/Reader.vue';
  12. //const Forum = () => import('./components/Forum/Forum.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. ['/income', Income ],
  29. ['/sources', Sources ],
  30. ['/settings', Settings ],
  31. ['/help', Help ],
  32. ['*', null, null, '/cardindex' ],
  33. ];
  34. let routes = {};
  35. for (let route of myRoutes) {
  36. const [path, component, name, redirect] = route;
  37. let cleanRoute = _.pickBy({path, component, name, redirect}, _.identity);
  38. let parts = cleanRoute.path.split('~');
  39. let f = routes;
  40. for (let part of parts) {
  41. const curRoute = _.assign({}, cleanRoute, { path: part });
  42. if (!f.children)
  43. f.children = [];
  44. let r = f.children;
  45. f = _.find(r, {path: part});
  46. if (!f) {
  47. r.push(curRoute);
  48. f = curRoute;
  49. }
  50. }
  51. }
  52. routes = routes.children;
  53. Vue.use(VueRouter);
  54. export default new VueRouter({
  55. routes
  56. });