Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05758c1

Browse files
committed
fix: doscsearch weird behavior on click
1 parent7b83485 commit05758c1

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

‎src/components/AlgoliaDocSearch.vue‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function initialize() {
4646
4747
props: {
4848
href:hit.url,
49+
children,
4950
5051
onClick(event:MouseEvent) {
5152
if (isSpecialClick(event))return
@@ -62,39 +63,42 @@ function initialize() {
6263
// behavior to leverage the Router loading feature.
6364
if (route.path!==hitPathname)event.preventDefault()
6465
65-
router.push(hit.url)
66+
// router doesn't handle same-page navigation so we use the native
67+
// browser location API for anchor navigation
68+
if (route.path===hitPathname) {
69+
window.location.assign(window.location.origin+hit.url)
70+
}else {
71+
router.push(hit.url)
72+
}
6673
},
67-
68-
children,
6974
},
7075
}
7176
},
7277
})
7378
79+
// @ts-ignore: Unreachable code error
7480
docsearch(options)
7581
}
7682
83+
/**
84+
* Check if event is special click to avoid closing the DocSearch too soon.
85+
*/
7786
const isSpecialClick= (event:MouseEvent)=>
7887
event.button===1||
7988
event.altKey||
8089
event.ctrlKey||
8190
event.metaKey||
8291
event.shiftKey
8392
93+
/**
94+
* Gets the relative path from an absolute URL provided by the DocSearch instance.
95+
*/
8496
const getRelativePath= (absoluteUrl:string)=> {
8597
const { pathname, hash }=newURL(absoluteUrl)
86-
87-
returnpathname+hash
98+
const url=window.location.origin
99+
const relativeUrl=pathname.replace(url,'/')+hash
100+
returnrelativeUrl.replace(/\/+$/,'')
88101
}
89-
// function getRelativePath(absoluteUrl: string) {
90-
// const { pathname, hash } = new URL(absoluteUrl)
91-
// return (
92-
// pathname.replace(
93-
// /\.html$/,
94-
// site.value.cleanUrls === 'disabled' ? '.html' : ''
95-
// ) + hash
96-
// )
97-
// }
98102
99103
onMounted(()=> {
100104
initialize()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp