【问题标题】:react router dom fallback route with no layout在没有布局的情况下反应路由器 dom 后备路由
【发布时间】:2018-09-27 09:54:56
【问题描述】:

我有以下路线

  <Switch>
     <Route exact path='/login' component={Login} />
     <Layout>
         <Route exact path='/' component={Dashboard} />
         <Route exact path='/players' component={Players} />
         <Route path='/settings' component={Settings} />
     </Layout>
     <Route component={ErrorPage} />
  </Switch>

页面工作正常,但它永远不会落入错误页面, 它只是显示没有内容的空白布局

我希望登录页面和错误页面都没有布局,我该怎么做

【问题讨论】:

    标签: reactjs react-router react-router-dom


    【解决方案1】:

    对于您的特定用例,不要在路由器中定义布局组件。为每个组件创建自定义路由器,为每个组件定义渲染布局,除了登录和错误页面。您可以参考以下网址了解更多信息 https://simonsmith.io/reusing-layouts-in-react-router-4/

    【讨论】:

      猜你喜欢
      • 2023-01-13
      • 2017-06-24
      • 2017-12-11
      • 2017-12-21
      • 2021-08-06
      • 2022-01-21
      • 1970-01-01
      • 2020-07-29
      • 2017-02-04
      相关资源
      最近更新 更多