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 @@ - - -