簡體   English   中英

路由路由器v4無法反映鏈接的組件更改?

[英]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>
    )
  }
}

https://codesandbox.io/s/r433m6kvvp

變化:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM