fix: normalize path for search result

This commit is contained in:
Justineo
2021-10-22 17:04:26 +08:00
parent b8432a870e
commit 2a59d493a5
2 changed files with 13 additions and 3 deletions

View File

@@ -27,6 +27,15 @@ function isSpecialClick (event) {
event.shiftKey
)
}
function normalizeURL (url) {
if (url.endsWith('/')) {
return url.slice(0, -1)
}
return url.replace(/\/([#?])/, '$1')
}
export default {
name: 'one-search',
components: {
@@ -90,10 +99,11 @@ export default {
})
},
hitComponent: ({ hit, children }) => {
const url = normalizeURL(hit.url)
return createElement(
'a',
{
href: hit.url,
href: url,
onClick: event => {
if (isSpecialClick(event)) {
return
@@ -112,7 +122,7 @@ export default {
if (this.$router.history.current.path !== hitPathname) {
event.preventDefault()
}
this.$router.push(hit.url)
this.$router.push(url)
},
children
}