The history is undefined, while trying to call this.props.history.push("/home").
Code:
Index.js
const rootElement = document.getElementById("root");
const root = createRoot(rootElement);
root.render(
<HashRouter>
<App location />
</HashRouter>
);
App.js
export class App extends React.Component {
handleClick = () => {
this.props.history.push("/home");
};
render() {
return (
<div className="App">
<button onClick={() => this.handleClick()}>Click to Nav</button>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
}
React-Router: v5.2.0
CodeSandbox link: https://codesandbox.io/s/sharp-wing-ju5ou9?file=/src/App.js