我的应用程序中有以下代码:
应用
<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
变量,即使我在不同的页面,我也会得到与空params
,path: '/', url: '/'
相同的默认对象(可能是仪表板路径)。为什么会这样?
所以解决方案是将qazxsw poi放在qazxsw poi中通过qazxsw poi定义的每个页面中。如果有人知道更好的解决方案,请告诉我。