Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hashRouter anchor #648

Closed
wants to merge 1 commit into from
Closed

hashRouter anchor #648

wants to merge 1 commit into from

Conversation

nikomal
Copy link

@nikomal nikomal commented Apr 3, 2019

Summary

if a website handle route by HashRouter. such as: react-router. then the url will has char '#', but it isn`t mean an anchor link. so in search result, the anchor will not append in url

Result
exclude the string like '#/*'. if url has '#/', it will be recognized as a route, not an anchor.

@s-pace
Copy link

s-pace commented Apr 4, 2019

👋 @nikomal

Could you provide us a live example of the issue this PR will solve? We would try to reproduce it in order to fully understand your issue.

It seems that the current implementation works with website handling route by HashRouter. You can have a look on the signal documentation for example.

@nikomal
Copy link
Author

nikomal commented Apr 4, 2019

👋 @s-pace

https://sheinsight.github.io/shineout/1.2.x/en#/ just like this link.

the website use hashRouter and docsearch.js, but in the search result. because of the url has '#'. so the result link does not has the anchor. this is special scene. it need both hashRouter and anchor link.

@s-pace
Copy link

s-pace commented Apr 4, 2019

Thanks for the details. Given the way an URL is built and how a fragment is built from an URL, we consider that an URL generally contains one impactful #.

However, what you aim to do is definitely doable thanks to the transformdata method. You can use it in this way:

 docsearch({
    apiKey: '25626fae796133dc1e734c6bcaaeac3c',
    indexName: 'docsearch',
    inputSelector: '#q',
    transformData: function(hits) {
      // modify hits
      hits.map(hit => hit.url = hit.url + "#" + hit.anchor)
      return hits;
    },
    debug: false // Set debug to true if you want to inspect the dropdown
  });

s-pace pushed a commit to algolia/docsearch-configs that referenced this pull request Apr 4, 2019
@s-pace
Copy link

s-pace commented Apr 4, 2019

Closing this PR since my previous comments solved the issues raised.
@nikomal feel free to re-open it if needed.

@s-pace s-pace closed this Apr 4, 2019
@siduck siduck mentioned this pull request Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants