I'm building a search UI using React, React Router and the awesome Reactivesearch library. I'm trying to figure out how I can prevent users from simply navigating to mydomain.com/search, since that is my search results route.
Ideally, if users tried to navigate to mydomain.com/search, I will use RR Redirect component to redirect to the home page.
I'm using "/search"
for the route that the Route component in RR(v5) to render the search results page and can't quite figure out how to use something like /search?q=${value}
to render the page?
As a preface I do have this in the render block (I'm using class based component for search results)
let value = JSON.stringify(queryString.parse(location.search));
if (this.value === '' || null) {
return (
<Redirect to="/" />
);
}
However, its not working... I can still go to my address bar and type in mydomain.com/search and the page renders.
Here is an example in my SearchResults.tsx:
<Route path = "/search" render={() => (
<ReactiveList
...
...
/>
/>
I'm trying to get to
<Route path = `/search?q="${value}"` render={() => (
<ReactiveList
...
...
/>
/>
Update Docs on ReactiveList Example from docs:
<ReactiveList
componentId="SearchResult"
dataField="ratings"
pagination={false}
paginationAt="bottom"
pages={5}
sortBy="desc"
size={10}
loader="Loading Results.."
showResultStats={true}
renderItem={res => <div>{res.title}</div>}
renderResultStats={function(stats) {
return `Showing ${stats.displayedResults} of total ${stats.numberOfResults} in ${
stats.time
} ms`;
}}
react={{
and: ['CitySensor', 'SearchSensor'],
}}
/>
How can I prevent users from simply navigating to mydomain.com/search ??