Skip to content

Commit

Permalink
fix: remove duplicate router logic (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Jul 29, 2022
1 parent fb9cee9 commit 63584c2
Showing 1 changed file with 1 addition and 42 deletions.
43 changes: 1 addition & 42 deletions src/client/theme-default/components/VPAlgoliaSearchBox.vue
Expand Up @@ -60,63 +60,22 @@ function initialize(userOptions: DefaultTheme.AlgoliaSearchOptions) {
},
hitComponent({ hit, children }: { hit: any; children: any }) {
const relativeHit = hit.url.startsWith('http')
? getRelativePath(hit.url as string)
: hit.url
return {
__v: null,
type: 'a',
ref: undefined,
constructor: undefined,
key: undefined,
props: {
href: hit.url,
onClick(event: MouseEvent) {
if (isSpecialClick(event)) {
return
}
// we rely on the native link scrolling when user is already on
// the right anchor because Router doesn't support duplicated
// history entries.
if (route.path === relativeHit) {
return
}
// if the hits goes to another page, we prevent the native link
// behavior to leverage the Router loading feature.
if (route.path !== relativeHit) {
event.preventDefault()
}
router.go(relativeHit)
},
children
}
props: { href: hit.url, children }
}
}
})
docsearch(options)
}
function isSpecialClick(event: MouseEvent) {
return (
event.button === 1 ||
event.altKey ||
event.ctrlKey ||
event.metaKey ||
event.shiftKey
)
}
function getRelativePath(absoluteUrl: string) {
const { pathname, hash } = new URL(absoluteUrl)
return pathname + hash
}
</script>
Expand Down

0 comments on commit 63584c2

Please sign in to comment.