- 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.
Custom widgets have lifecycle hooks for each of the widget stages: init
, render
, and dispose
.
The render
stage runs when Algolia sends results: in other words, when a user types something.
Use it as follows:
JavaScript
Handle a Manual Editor rule redirect
If a redirect was created in the Manual Editor, handle it with InstantSearch’squeryRuleCustomData
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 the queryRuleCustomData
widget to update the page location when userData
contains a redirect.
JavaScript
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
queryRuleCustomData
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