I'm new to React(1 week :P). I have an app that hits an api based on a search term. From those results a user is able to favorite items from the results. When a I clicks on the link for favorites, I am directed to the correct component and the url reflects this change. However, when I enter a new search term, from the side navigation bar that is statically there always, I am presented with the correect information in the correct component, but the url does not change; it still says http://localhost:3000/favorites where it should be http://localhost:3000. Here is the relevant code, if there is any more that you feel is needed to hazard a guess please let me know.
The routes:
return(
<BrowserRouter >
<div className='routes'>
<Route path='/' component={App}/>
<Route path='/favorites' component={Favorites}/>
</div>
</BrowserRouter>
) }
The SearchBox component:
return(
<form className="search-box" >
<input type="text" placeholder="Search.." name="search" autoComplete='off'/>
<button className="fa fa-search" type="submit" onClick={this.handleSearch.bind(this)}>
</button>
</form>
)
And the SideNav component with the links:
return(
<nav className='naviagtion'>
<ul className='mainmenu'>
<div className='img-logout'>
<img src={this.props.info.image} alt='Avatar' />
<Logout handleLogout={this.handleLogout.bind(this)}/>
</div>
<SearchBox search={this.searchHandler.bind(this)}/>
<li>
<a href="/">home</a>
</li>
<li>
<a href="/favorites">favorites</a>
</li>
<li>
<a href="">playlists</a>
<ul className='submenu'>
<li>
<a href="">
<strong>list of lists</strong>
</a>
</li>
</ul>
</li>
<li>
<a href="">friends</a>
</li>
</ul>
</nav>
)
I've seen a lot of information of the url changing but the component not rendering. That is not my problem. Then component is rendering correctly, however the url is not reflecting that.
EDIT:
Here is where the SideBar is being rendered in the Home Component.
<div>
<SideBar
info={this.state.info}
logout={this.handleLogout.bind(this)}
search={this.handleSearch.bind(this)}
/>
<Main videos={this.state.videos}/>
</div>
And here is the App.js
<div className='App'>
{localStorage.userData === undefined
? this.renderLogin()
: <Home logout={this.logout.bind(this)} deets=
{localStorage.userData}/>}
</div>