when I started the project I did not work with create-react-app I built the basic react-flux app like always which is with browserify and babelify and all and the react-router v4 was working and no problem happened
then I immigrated to create-react-app env to use the testing and building tools that is offered
and I installed all packages that I used previously properly but react-router v4 had a problem
when I click NavLink, it does not change the URL but when I change the URL manually it works fine
I use BrowserRouter like this:
<BrowserRouter history={HashRouter}<App /></BrowserRouter>,document.getElementById("root"));
And NavLink like this:
<NavLink className="nav-link" activeClassName="active" to={"/drugs"}>
<i className="fa fa-medkit" aria-hidden="false"/>
Drugs
</NavLink>
And Router like this:
<Switch>
<Route exact={true} path="/" component={Patients}/>
<Route exact path="/drugs" component={Drugs}/>
<Route exact path="/settings" component={Settings}/>
<Route path="*" component={Error}/>
</Switch>
and thanks in advance.
Most likely your component does not update properly. This can happen if you inherit from
React.PureComponent
instead ofReact.Component
or mess up with the methodshouldComponentUpdate()
.If you can't figure it out (you should), you can still pass the
location
object manually with the HOCwithRouter
fromreact-router-dom
like so :