Refactor routing of of hashtag links

This commit is contained in:
Wolfgang Huß 2019-09-13 13:58:59 +02:00 committed by roschaefer
parent ee8ce5a153
commit 0157cc3700
3 changed files with 17 additions and 14 deletions

View File

@ -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])}`)
}

View File

@ -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) => {

View File

@ -1,13 +0,0 @@
<template>
<div></div>
</template>
<script>
export default {
mounted() {
let { id: hashtag } = this.$route.params
// 'hashtag' seems automatically to be 'decodeURI' (on macOS Firefox). Don't know if this is always the case.
this.$router.push({ path: '/', query: { hashtag: encodeURI(hashtag) } })
},
}
</script>