Доработка маршрутов
This commit is contained in:
@@ -4,6 +4,7 @@ import _ from 'lodash';
|
|||||||
|
|
||||||
import App from './components/App.vue';
|
import App from './components/App.vue';
|
||||||
import CardIndex from './components/CardIndex/CardIndex.vue';
|
import CardIndex from './components/CardIndex/CardIndex.vue';
|
||||||
|
import Search from './components/CardIndex/Search/Search.vue';
|
||||||
import Reader from './components/Reader/Reader.vue';
|
import Reader from './components/Reader/Reader.vue';
|
||||||
//import Forum from './components/Forum/Forum.vue';
|
//import Forum from './components/Forum/Forum.vue';
|
||||||
import Income from './components/Income/Income.vue';
|
import Income from './components/Income/Income.vue';
|
||||||
@@ -14,7 +15,9 @@ import NotFound404 from './components/NotFound404/NotFound404.vue';
|
|||||||
|
|
||||||
const myRoutes = [
|
const myRoutes = [
|
||||||
['/', null, null, '/cardindex'],
|
['/', null, null, '/cardindex'],
|
||||||
['/cardindex', CardIndex ],
|
['/cardindex', CardIndex, null, '/cardindex/search' ],
|
||||||
|
['/cardindex~search', Search ],
|
||||||
|
//['/cardindex~card/:authorId', CardIndex ],
|
||||||
['/reader', Reader ],
|
['/reader', Reader ],
|
||||||
['/income', Income ],
|
['/income', Income ],
|
||||||
['/sources', Sources ],
|
['/sources', Sources ],
|
||||||
@@ -23,13 +26,29 @@ const myRoutes = [
|
|||||||
['*', NotFound404 ],
|
['*', NotFound404 ],
|
||||||
];
|
];
|
||||||
|
|
||||||
let routes = [];
|
let routes = {};
|
||||||
|
|
||||||
for (let route of myRoutes) {
|
for (let route of myRoutes) {
|
||||||
const [path, component, name, redirect] = route;
|
const [path, component, name, redirect] = route;
|
||||||
let r = _.pickBy({path, component, name, redirect}, _.identity);
|
let cleanRoute = _.pickBy({path, component, name, redirect}, _.identity);
|
||||||
routes.push(r);
|
|
||||||
|
let parts = cleanRoute.path.split('~');
|
||||||
|
let f = routes;
|
||||||
|
for (let part of parts) {
|
||||||
|
const curRoute = _.assign({}, cleanRoute, { path: part });
|
||||||
|
|
||||||
|
if (!f.children)
|
||||||
|
f.children = [];
|
||||||
|
let r = f.children;
|
||||||
|
|
||||||
|
f = _.find(r, {path: part});
|
||||||
|
if (!f) {
|
||||||
|
r.push(curRoute);
|
||||||
|
f = curRoute;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
routes = routes.children;
|
||||||
|
|
||||||
Vue.use(VueRouter);
|
Vue.use(VueRouter);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user