This is the React InstantSearch v7 documentation.
If you’re upgrading from v6, see the upgrade guide.
If you were using React InstantSearch Hooks,
this v7 documentation applies—just check for necessary changes.
To continue using v6, you can find the archived documentation.
- Searching for “help” redirects users to a support page
- Searching for a category, such as, “TV” redirects users to a category page
- Searching for a specific product or brand redirects users to a seasonal promotional page for it
- Searching for specific keywords related to an ongoing event, such as, “masks”, redirects users to a more specific landing page
- If a redirect was created in the Manual Editor, handle it with InstantSearch’s
queryRuleCustomData
widget. - If a redirect was created in the Visual Editor, you must create a custom InstantSearch widget to handle redirects.
Handle a Visual Editor rule redirect
Configure the redirect with a custom widget
If a redirect was created in the Visual Editor, the API response contains therenderingContent.redirect
property which, in turn, contains the redirect URL
.
To access this property from InstantSearch, you must create a custom widget.
A custom widget can get up-to-date results from the useInstantSearch()
Hook.
Use it as follows:
React
Handle a Manual Editor rule redirect
If a redirect was created in the Manual Editor, handle it with InstantSearch’sQueryRulesCustomData
widget.
Configure a rule
To set up a rule that returns custom data whenever the query matches specific keywords, see Create a rule for returning custom data.Configure the queryRuleCustomData widget
After setting up a rule that returns the custom redirect data, you can use theQueryRulesCustomData
widget to update the page location when userData
contains a redirect.
React
Offer a suggested redirect rather than a hard redirect
The preceding is an example of a “hard redirect”, which forces users to a specific URL. This works in most situations, but sometimes you might want to suggest a redirect URL rather than force it onto them. To do this, create the rule similarly but distinguish between “hard” and “suggested” redirects by ensuring the returned data is a JSON object. The object’s properties are:- name (used to display the link)
- URL
- force (
true
for a hard redirect,false
for a suggested redirect).
JSON
QueryRulesCustomData
widget that had been previously defined needs updating to decide what happens to a user based upon the returned data.
To do this, the redirect check (within transformItems
) needs updating to decide whether to force the redirect onto users or not.
The default template also needs setting to display a user message with the specific redirect URL.
JavaScript