Reactjs 使用react路由器dom在子组件中进行路由

Reactjs 使用react路由器dom在子组件中进行路由,reactjs,react-router-dom,core-ui,Reactjs,React Router Dom,Core Ui,我将CoreUI Pro模板用于React仪表板,并尝试将登录功能集成到其中。我的登录使用的是AWS Cognito,所以我使用的是该部分的教程 我的问题是,一旦登录,链接就无法工作 下面是我的顶级routes.js export default ({ childProps }) => <HashRouter> <Switch> <AppliedRoute path='/' exact component={Login} props={

我将CoreUI Pro模板用于React仪表板,并尝试将登录功能集成到其中。我的登录使用的是AWS Cognito,所以我使用的是该部分的教程

我的问题是,一旦登录,链接就无法工作

下面是我的顶级routes.js

export default ({ childProps }) =>
  <HashRouter>
    <Switch>
      <AppliedRoute path='/' exact component={Login} props={childProps} />
      <UnauthenticatedRoute path='/login' exact component={Login} props={childProps} />
      <AuthenticatedRoute path='/dashboard' exact component={Full} props={childProps} />
      <Route component={NotFound} />
    </Switch>
  </HashRouter>
导出默认值({childProps})=>
在登录组件中,我重定向到/dashboard,这样就可以了。Full是包含仪表板的组件的名称

用户进入完整组件后,我希望他们能够在以下位置导航:

<Container fluid>
              <Switch>
                <Route path='/dashboard' name='Dashboard' component={Dashboard} />
                <Route path='/deliveries/listDeliveries' name='List Deliveries' component={ListDeliveries} />
                <Route path='/shifts/listShifts' name='List Shifts' component={ListShifts} />
                <Route path='/locations/' name='Locations' component={Locations} />
                <Redirect from='/' to='/dashboard' />
              </Switch>
            </Container>


在CoreUI模板中,这是可行的,但对我来说,如果登录后导航到/位置,它将转到我的404页面。我曾考虑将所有内容移动到routes.js,但问题是Full在页面周围有一个模板,它只是加载页面某个区域中的位置之类的组件

您正在嵌套管线-请参见示例以供参考

问题是,您在到
完整组件的路径中具有精确的属性,因此在浏览到
/位置
路径时,该组件不会呈现。我建议重组您的路线,这样您就可以像上面的示例一样构建路线(例如,
/dashboard/deliveries

然后,您将在顶级路由中省略exact属性,并在
Full
组件中保留如下路由:

<Route 
  path={this.props.match.url + '/deliveries/listDeliveries'}
  name='List Deliveries'
  component={ListDeliveries}
/>


这将匹配路径
/dashboard/deliveries/listDeliveries

谢谢,修复了它