From c1084b48a733e2347d76ba358f93c3783127d859 Mon Sep 17 00:00:00 2001 From: axolotle Date: Mon, 8 Mar 2021 19:16:02 +0100 Subject: [PATCH] improved query handling --- src/router/routes.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/router/routes.js b/src/router/routes.js index a457646..3f3135f 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -17,15 +17,17 @@ export default [ options: TextOptions }, props: { - default: ({ query }) => ({ - mode: query.mode || 'tree-map', + default: ({ query }) => { + let { mode = 'tree-map', texts = [] } = query + if (typeof texts === 'string') texts = [texts] // In case of a reload or direct link, vue-router doesn't turn the query string into an array. - texts: query.texts && query.texts.length && typeof query.texts[0] === 'string' - ? query.texts.map(text => text.split(',').map(id => parseInt(id))) - : query.texts - }), + if (texts && texts.length && typeof texts[0] === 'string') { + texts = texts.map(text => text.split(',').map(id => parseInt(id))) + } + return { mode, texts } + }, options: ({ query }) => ({ - show: !('texts' in query) + show: !('texts' in query && query.texts.length) }) } },