[英]route router v4 does not reflect component change with Link?
我的路線結構有什么問題? 使用鏈接導航無法看到更改。
class App extends React.Component {
render() {
return(
<BrowserRouter>
<div>
<AuthRoute></AuthRoute>
<Switch>
<Route path='' component={Home} />
<Route path='/profile' component={Profile} />
</Switch>
</div>
</BrowserRouter>
)
}
}
變化:
1-代替path=''
(空白路徑),使用path='/'
。
2-使用path='/'
exact
詞,否則在最后定義它,因為如果您不使用精確詞,則/
將與/profile
或任何其他路由匹配。
查看文檔以獲取有關確切和切換以及它們如何工作的更多詳細信息。
像這樣:
<Route exact path='/' component={Home} />
<Route path='/profile' component={Profile} />
要么
<Route path='/profile' component={Profile} />
<Route path='/' component={Home} />
工作守則 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.