From 3c06fd611e66bbb05fb10f74d5779fcc270a2726 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 2 Jan 2019 22:00:35 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BC=D0=B0=D1=80=D1=88=D1=80=D1=83=D1=82=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/router.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/client/router.js b/client/router.js index 3b950fd5..c8241554 100644 --- a/client/router.js +++ b/client/router.js @@ -4,6 +4,7 @@ import _ from 'lodash'; import App from './components/App.vue'; import CardIndex from './components/CardIndex/CardIndex.vue'; +import Search from './components/CardIndex/Search/Search.vue'; import Reader from './components/Reader/Reader.vue'; //import Forum from './components/Forum/Forum.vue'; import Income from './components/Income/Income.vue'; @@ -14,7 +15,9 @@ import NotFound404 from './components/NotFound404/NotFound404.vue'; const myRoutes = [ ['/', null, null, '/cardindex'], - ['/cardindex', CardIndex ], + ['/cardindex', CardIndex, null, '/cardindex/search' ], + ['/cardindex~search', Search ], + //['/cardindex~card/:authorId', CardIndex ], ['/reader', Reader ], ['/income', Income ], ['/sources', Sources ], @@ -23,13 +26,29 @@ const myRoutes = [ ['*', NotFound404 ], ]; -let routes = []; +let routes = {}; for (let route of myRoutes) { const [path, component, name, redirect] = route; - let r = _.pickBy({path, component, name, redirect}, _.identity); - routes.push(r); + let cleanRoute = _.pickBy({path, component, name, redirect}, _.identity); + + 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);