React router v4 - 匹配对象的错误内容

问题描述 投票:0回答:1

我的应用程序中有以下代码:

应用

<BrowserRouter>
  <div className="app">
    <Switch>
      <Route path={ getRoutePath('login') } component={ LoginSection } />
      <Route path={ getRoutePath('dashboard') } component={ AuthenticatedSection } />
    </Switch>
  </div>
</BrowserRouter>

AuthenticatedSection组件

<div className="authenticated-layout">
  { authenticatedUser.isFetching === false &&
    <div>
      <HeaderContainer />
      <div className="wrapper">
        <AuthenticatedRoutesSwitch />
      </div>
      <FooterContainer />
    </div>
  }
</div>

AuthenticatedRoutesSwitch

<Switch>
  <Route exact path={ getRoutePath('dashboard') } render={ this.redirectToWorkspaces } />
  <Route path={ getRoutePath('workspace.configuration.create') } component={ ConfigurationCreatePage } />
 <Route path={ getRoutePath('workspace.show') } component={ WorkspaceShowPage } />
 <Route path={ getRoutePath('workspace.list') } component={ WorkspaceListPage } />

  <Route exact path={ getRoutePath('administration') } render={ this.redirectToUsersAdministration } />
  <AdminProtectedRoute path={ getRoutePath('administration.users') } component={ UserListPage } />
  <AdminProtectedRoute path={ getRoutePath('administration.oauth') } component={ OAuthListPage } />

  <Route path={ getRoutePath('trash.list') } component={ TrashList } />
</Switch>

我的问题是,如果我将在this.props.match组件或<HeaderContainer />中访问AuthenticatedSection变量,即使我在不​​同的页面,我也会得到与空paramspath: '/', url: '/'相同的默认对象(可能是仪表板路径)。为什么会这样?

reactjs react-router react-router-v4
1个回答
0
投票

所以解决方案是将qazxsw poi放在qazxsw poi中通过qazxsw poi定义的每个页面中。如果有人知道更好的解决方案,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.