Skip to content

Display search query in URL #629

Answered by nhoizey
xplosionmind asked this question in Q&A
Discussion options

You must be logged in to vote

@xplosionmind if you add the query string to the URL, you should also use it to run the search when arriving on the page.

Here's how I did it on my search page:

const params = new URLSearchParams(window.location.search);
if (params.has('q')) {
  search_ui.triggerSearch(params.get('q'));
}

My full code here: https://github.com/nhoizey/nicolas-hoizey.photo/blob/main/src/search/index.njk

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@xplosionmind
Comment options

@xplosionmind
Comment options

@nhoizey
Comment options

Answer selected by xplosionmind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants