我有一個反應應用程序,充當儀表板並顯示不同 React應用程序的鏈接。用戶可以通過單擊按鈕來選擇應用程序。
總之,我需要根據用戶選擇重定向到不同的URL。如何在React中重定向
在下面的示例代碼中,嘗試使用withRouter重定向到URL。然而它給出了以下錯誤: TypeError:無法讀取屬性「推」的未定義
我使用的是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);
我更新了我的答案。它有幫助嗎? –