3 回答

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超4個(gè)贊
var r = this;
if statement
根據(jù)醫(yī)生的說法:
歷史對(duì)象通常具有以下屬性和方法:
長度-(數(shù)字)歷史堆棧中的條目數(shù) 操作-(字符串)當(dāng)前操作(推送、替換或彈出)
位置-(對(duì)象)當(dāng)前位置??赡芫哂邢铝袑傩裕?/trans>
路徑名-(字符串)URL的路徑 搜索-(字符串)URL查詢字符串 散列-(字符串)URL散列片段 狀態(tài)-(字符串)位置特定的狀態(tài),當(dāng)這個(gè)位置被推送到堆棧上時(shí),它被提供給例如Push(path,state)。僅在瀏覽器和內(nèi)存歷史記錄中可用。 推動(dòng)(路徑,[狀態(tài)])-(函數(shù))將一個(gè)新條目推到歷史堆棧上 替換(path,[state])-(函數(shù))替換歷史堆棧上的當(dāng)前條目 Go(N)-(函數(shù))通過n個(gè)條目移動(dòng)歷史堆棧中的指針 GoBack()-(函數(shù))等價(jià)于go(-1) GoForward()-(函數(shù))等價(jià)于go(1) 塊(提示)-(函數(shù))阻止導(dǎo)航
this.props.history.push({ pathname: '/template', search: '?query=abc', state: { detail: response.data }})
Link
Redirect
<Link to={{ pathname: '/template', search: '?query=abc', state: { detail: response.data } }}> My Link </Link>
/template
this.props.location.state.detail
withRouter
.
根據(jù)文件:
帶路由器
您可以訪問歷史對(duì)象的屬性和最近的 <Route>'s
匹配通過 withRouter
高階部件。 withRouter
每次路由發(fā)生變化時(shí),都會(huì)重新呈現(xiàn)其組件。 <Route>
渲染 props: { match, location, history }
.

TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊
如果您需要傳遞URL參數(shù)
推組件:
this.props.history.push(/home:${this.state.userID})
在路由器組件上定義路由:
<Route path='/home:myKey' component={Home} />
關(guān)于家庭部分:
componentDidMount(){ const { myKey } = this.props.match.params console.log(myKey ) }
添加回答
舉報(bào)