简体   繁体   English

路由路由器v4无法反映链接的组件更改?

[英]route router v4 does not reflect component change with Link?

What's wrong with my route structure? 我的路线结构有什么问题? Used Link to navigate couldn't see the changes. 使用链接导航无法看到更改。

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 https://codesandbox.io/s/r433m6kvvp

Changes: 变化:

1- Instead of path='' (blank path) use path='/' . 1-代替path='' (空白路径),使用path='/'

2- Use exact word with path='/' otherwise define that in that last, because if you don't use exact then / will match with /profile or any other route also. 2-使用path='/' exact词,否则在最后定义它,因为如果您不使用精确词,则/将与/profile或任何其他路由匹配。

Check the doc for more details about exact and Switch and how they work. 查看文档以获取有关确切切换以及它们如何工作的更多详细信息。

Like this: 像这样:

<Route exact path='/' component={Home} />
<Route path='/profile' component={Profile} />

or 要么

<Route path='/profile' component={Profile} />
<Route path='/' component={Home} />

Working Code . 工作守则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM