0

I'm building a search application and am trying to get some results links that appear in tab format to work. Much like you see on google.com/search=?user_query and bing.com/search=?user_query... where after you submit the initial query, you can click on "Images", "Shopping" and "News" for example and a different results view is rendered based on the the result link/tab that you clicked.

I'm using ReactiveSearch to build my search UI. So far I have this:

ResultNavigationTabs.tsx to build the link tabs

class ResultNavigationTabs extends Component {
  
  render() {
    const { classes, items, location: { pathname } } = this.props;

    return (
      <ul className={classes.nav}>
        {items.map(item => (
          <Link to={item.link} key={item.text}>
            <li className={item.link.startsWith(pathname) ? "active" : ""}>
              {item.text}
            </li>
        </Link>
        ))}
      </ul>
    );
  }
}

export default withStyles(styles)(withRouter(ResultNavigationTabs));

I then render this component in my ResultsViewPage.tsx like so:

render() {
const { selected } = this.state;

...(omitted for brevity)

<ResultNavigationTabs2
   className={classes.myNavigationTabs}
     items={[
       { text: "Web", link: `/search?q="${selected}"` },
       { text: "News", link: `/news?q="${selected}"` },
       { text: "Shopping", link: `/shopping?q="${selected}"` },
     ]}
 />

The links do render but they do not work. If I hover over the links, the search query string is empty (http://localhost:3000/search?q=%22%22). If you've worked with ReactiveSearch, it should be: http://localhost:3000/search?q=%22user%20query%22.

I have had it working but only when I render ResultNavigationTabs in the same file as the search box (DataSearch in ReactiveSearch language). However, if I do that it appears right below the search box in the Header instead of the results area.

I need to figure out a way to render ResultNavigationTabs in the ResultsViewPage.tsx file with working links.

user3125823
  • 1,846
  • 2
  • 18
  • 46

1 Answers1

1

After doing some more thoughtful searching, I found the answer right here on SO! Comes complete with 2 CodeSandBox demos as well - check them out.

user3125823
  • 1,846
  • 2
  • 18
  • 46