使用Reaction路由器V4以編程方式導航我剛剛換了react-router從第3節到第4節。的成員函數中如何以編程方式導航。Component..在.handleClick()函數,我想導航到/path/some/where在處理了一些數據之后。我以前是這樣做的:import { browserHistory } from 'react-router'browserHistory.push('/path/some/where')但我在v4中找不到這樣的接口。如何使用v4導航?
3 回答

蝴蝶刀刀
TA貢獻1801條經驗 獲得超8個贊
this.props.history.push("/new/url")
您可能想通過 history
prop
從父組件到組件,如果操作不可用,則調用該操作。

白衣非少年
TA貢獻1155條經驗 獲得超0個贊
Redux-Saga
<Router>
元件React-Router
步驟:
安裝歷史NPM模塊- yarn add history
或npm install history --save
創建一個名為 history.js
在你的 App.js
級別文件夾(這是我的首選) // src/history.jsimport createHistory from 'history/createBrowserHistory';export default createHistory();`
將此歷史記錄對象添加到您的路由器組件中,如下所示 // src/App.jsimport history from '../your/path/to/history.js;'<Router history={history}>// Route tags here</Router>
通過導入來調整URL,就像以前一樣 你的全球歷史目標: import history from '../your/path/to/history.js;'history.push('new/path/here/');
- 3 回答
- 0 關注
- 664 瀏覽
添加回答
舉報
0/150
提交
取消