Passing and Accessing a hit after Click

Hey everyone! I’m new here but have been lurking in the background for a while. I’m in love with Aloglia and what it promises, but before I dive in I have a question.

In my implementation I would be showing lots of product to the consumer and they need to be able to click on these objects. There are some ways to pass data between web pages but I was wondering if Algolia has anything specific to them? Essentially, passing the Hit object data and being able to access all the variable with that object on a sequential page.

1 Like

We don’t impose any particular way to do that, because passing through data depends so much on your environment.

There are two main methods can be done. The first method is the traditional way of having a detail page for each object in your database. The second method is by actually passing around the hit data.

The first method is usually the preferred one because you can have a limited set of data to retrieve when searching, but when displaying a detail page you have the space to display a lot of other related information.

When doing the second method, it really depends on what you want to achieve directly. It’s easy to stringify the data and then put them in the query string, to then go to a detail page with that information. You can also for example store it in localstorage.

To give you more focused information, I’ll have to have more information on what exactly you want to achieve.

Have a splendid day!

Well lets use the movies example that Algolia loves. Lets say you search through all that just like before but now when you click on a movie it takes you to a feature page giving you more information about that object clicked.

In the search you see the image and title but when you click you see all that and a video + description + other stuff.


1 Like

So as I said, the traditional way of doing that would be by making the items into a link, then linking to /products/[[theObjectID]]

This is done on the Yarn website for example.

Once you go to that page, you can use your own method of fetching data from your database, based on that objectID. If all your data is safely replicated in Algolia, and more data from there is all what’s needed, you can then on that detail page do index.getObject(objectID).then(content => /* render your detail page */). You can see that pattern here

Does this make sense?

1 Like

yea, totally! thanks!

1 Like

I ended up just using the hit data for the object and passed it to a dynamic modal. This worked really well and I didn’t have to mess with multiple pages.

That also works if you don’t have any data not in Algolia, good luck with your project! :heart: