mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Refactor routing of of hashtag links
This commit is contained in:
parent
ee8ce5a153
commit
0157cc3700
16
webapp/middleware/searchHashtag.js
Normal file
16
webapp/middleware/searchHashtag.js
Normal 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])}`)
|
||||
}
|
||||
@ -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) => {
|
||||
|
||||
@ -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>
|
||||
Loading…
x
Reference in New Issue
Block a user