go back on button click react code example
Example 1: how to make back button react
const BrowserHistory = require('react-router/lib/BrowserHistory').default;
const App = React.createClass({
render: () => {
return (
<div><button onClick={BrowserHistory.goBack}>Go Back</button></div>
);
}
});
React.render((
<Router history={BrowserHistory}>
<Route path="/" component={App} />
</Router>
), document.body);
Example 2: how to go back in usinsg router hisotry
this.props.history.goBack(); //react-router (v4)