From 0157cc3700f42b8c2885502c5ea396f5b6256435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Fri, 13 Sep 2019 13:58:59 +0200 Subject: [PATCH] Refactor routing of of hashtag links --- webapp/middleware/searchHashtag.js | 16 ++++++++++++++++ webapp/nuxt.config.js | 2 +- webapp/pages/search/hashtag/_id.vue | 13 ------------- 3 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 webapp/middleware/searchHashtag.js delete mode 100644 webapp/pages/search/hashtag/_id.vue diff --git a/webapp/middleware/searchHashtag.js b/webapp/middleware/searchHashtag.js new file mode 100644 index 000000000..a1bdda7e9 --- /dev/null +++ b/webapp/middleware/searchHashtag.js @@ -0,0 +1,16 @@ +import { exec, build } from 'xregexp/xregexp-all.js' + +export default async ({ store, env, route, redirect }) => { + let publicPages = env.publicPages + // only affect non public pages + if (publicPages.indexOf(route.name) >= 0) { + return true + } + + const regX = build('^/search/hashtag/((\\pL+[\\pL0-9]*)|([0-9]+\\pL+[\\pL0-9]*))$') + const matchHashtag = exec(decodeURI(route.name), regX) + + if (!matchHashtag) return true + + return redirect(`/?hashtag=${encodeURI(matchHashtag[0])}`) +} diff --git a/webapp/nuxt.config.js b/webapp/nuxt.config.js index 858294f37..5942d34e0 100644 --- a/webapp/nuxt.config.js +++ b/webapp/nuxt.config.js @@ -123,7 +123,7 @@ export default { ], router: { - middleware: ['authenticated', 'termsAndConditions'], + middleware: ['authenticated', 'termsAndConditions', 'searchHashtag'], linkActiveClass: 'router-link-active', linkExactActiveClass: 'router-link-exact-active', scrollBehavior: (to, _from, savedPosition) => { diff --git a/webapp/pages/search/hashtag/_id.vue b/webapp/pages/search/hashtag/_id.vue deleted file mode 100644 index 38364d86f..000000000 --- a/webapp/pages/search/hashtag/_id.vue +++ /dev/null @@ -1,13 +0,0 @@ - - -