I have a react app that acts as a dashboard and displays links for different
React applications. Users can select the application by clicking a button.
In short I need to redirect to a different URL based on user selection.
In the sample code below, trying to redirect to a URL using withRouter. However its giving the below error: TypeError: Cannot read property 'push' of undefined
I am using React 15.6.1.
index.js
render(
<BrowserRouter>
<Home />
</BrowserRouter>, document.getElementById('app')
);
home.js
class Home extends React.Component {
constructor(props) {
super(props);
this.loadApp1 = this.loadApp1.bind(this);
}
loadApp1() {
this.props.route.push('/app1');
}
render() {
return (
<div>
<button onClick={this.loadApp1}>App1</button>
</div>
);
}
}
export default withRouter(Home);