I'm creating web app using react and currently I'm having an issue when when navigating through the pages. Following is the detailed description. Hope some one can assist me.
My component (Task) is like this (simplyfied)
class Tasks extends Component {
constructor(props) {
super(props);
this.type = props.match.params.type;
}
render(){
return ( <h1>{this.type} </h1> );
}
}
And I do the routing from a seperate component using react-router-dom as following
:
:
import {BrowserRouter as Router, Route, Switch, Redirect} from 'react-router-dom'
:
<Route path={"/tasks/:type/"} component={Tasks} />
Finally I'm calling this routing component from one of my navigation menu by setting the urls as following
import MenuItem from 'material-ui/Menu/MenuItem';
<MenuItem>
<Link name="application_creation" to="/tasks/type1">Type One</Link>
</MenuItem>
<MenuItem>
<Link name="application_creation" to="/tasks/type2">Type Two</Link>
</MenuItem>
With this implementation, when i select a one url (from the navigation menu) it does not work as expected. When one is selected and then select the other one, it does not navigate as expected. If i type the url on the browser or refresh the page, it directs to the correct page (other url).
Hope I made my question clear :D . Can some one guide me in the right direction on how to fix this please?
Thanks
HashRouterinstead ofBrowserRouter- it will simplify the development process as it just works as you would expect. Once you've developed your app, you can look into re-factoring toBrowserRouter.return ( <h1>{this.type} </h1> );- ifprops.typechanges, this won't update as you only sync it in the constructor