@@ -46,6 +46,7 @@ function initialize() {
4646
4747 props: {
4848 href:hit .url ,
49+ children ,
4950
5051 onClick(event : MouseEvent ) {
5152if (isSpecialClick (event ))return
@@ -62,39 +63,42 @@ function initialize() {
6263// behavior to leverage the Router loading feature.
6364if (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
7480docsearch (options )
7581}
7682
83+ /**
84+ * Check if event is special click to avoid closing the DocSearch too soon.
85+ */
7786const isSpecialClick= (event : MouseEvent )=>
7887event .button === 1 ||
7988event .altKey ||
8089event .ctrlKey ||
8190event .metaKey ||
8291event .shiftKey
8392
93+ /**
94+ * Gets the relative path from an absolute URL provided by the DocSearch instance.
95+ */
8496const getRelativePath= (absoluteUrl : string )=> {
8597const { pathname, hash }= new URL (absoluteUrl )
86-
87- return pathname + hash
98+ const url= window .location .origin
99+ const relativeUrl= pathname .replace (url ,' /' )+ hash
100+ return relativeUrl .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
99103onMounted (()=> {
100104initialize ()