I've tried all possible versions but goBack() button does not work. Not sure what I am doing wrong but I was following this solution:
Anyway here is the code I am trying and I have feeling that there is something to do with HashRouter. Also How can I put the button in Navbar instead of calling it in App?
import React from 'react';
import { HashRouter, Route, withRouter } from 'react-router-dom';
import Home from "./components/Home";
import Navbar from "./components/Navbar";
import store from './store'
import PrivateRoute from './components/auth/PrivateRoute'
class App extends React.Component {
constructor(props){
super(props);
this.goBack = this.goBack.bind(this); // i think you are missing this
}
componentDidMount(){
store.dispatch(loadUser())
}
goBack(){
this.props.history.goBack();
}
render(){
return (
<Provider store={store}>
<HashRouter basename="/">
<Navbar />
<button onClick={this.goBack()}>Go Back</button>
<Route exact path="/" component={Home}/>
<PrivateRoute path="/aeons" component={AeonsList} />
</HashRouter>
</Provider>