UseHistory GOBACK
import {useHistory} from "react-router-dom";
const history = useHistory();
<button onClick={() => history.goBack()}>Go Back</button>
Defeated Dogfish
import {useHistory} from "react-router-dom";
const history = useHistory();
<button onClick={() => history.goBack()}>Go Back</button>
const history = useHistory()
const goBack = () => {
history.goBack()
}
return (
<button type="button" onClick={goBack}>
Go back
</button>
);
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);
this.props.history.goBack(); //react-router (v4)