algolia / docsearch

:blue_book: The easiest way to add search to your documentation.
https://docsearch.algolia.com
MIT License
3.95k stars 382 forks source link

v3 Configuration problems #1437

Open RayShineHub opened 2 years ago

RayShineHub commented 2 years ago

How do I need to configure to jump to the local station?

At present, my link is like this

my

It always refreshes the page again

But I want to be like your document, like this

your

RayShineHub commented 2 years ago

In fact, I want you to keep mouse click events, such as V2's handleselect(),which can customize the jump logic of the page

shortcuts commented 2 years ago

How do I need to configure to jump to the local station?

The extracted element (in the Crawler config) needs to be related or close enough (parent, sibling, children) to the anchor: e.g. here the vuepress-v3-template anchor is a children of h2, which is the element we index.

RayShineHub commented 2 years ago

hello @shortcuts

Searching in an article can realize the jump of the anchor point in the page, but when you click from the home page to the anchor point of searching an article, the website will be reloaded, which will cause some global components to be reloaded.

Can you use handleselect() to intercept the click event and jump the page through the Router , as in docSearch V2?

like this:

handleSelected: (input, event, suggestion) => {
  const { pathname, hash } = new URL(suggestion.url)
  instance.$router.push(`${pathname}${hash}`)
}

How do I need to configure to jump to the local station?

The extracted element (in the Crawler config) needs to be related or close enough (parent, sibling, children) to the anchor: e.g. here the vuepress-v3-template anchor is a children of h2, which is the element we index.

shortcuts commented 2 years ago

but when you click from the home page to the anchor point of searching an article, the website will be reloaded, which will cause some global components to be reloaded.

Ah yes it make sense, but there is indeed no click handler exposed on DocSearch v3. As a workaround, you can import the DocSearch component and add you own logic here

RayShineHub commented 2 years ago

Ah yes it make sense, but there is indeed no click handler exposed on DocSearch v3. As a workaround, you can import the DocSearch component and add you own logic here

Ah, but my website is based on Vue. If the import component changes a lot, I hope DocSearch V3 can expose click handler exposed. Like V2, I believe it is beneficial to many players!

What do you think?

RayShineHub commented 2 years ago

hello @shortcuts Can you write an example of a custom hitcomponent component based on vue 3