在某些路线上隐藏布局

时间:2019-09-02 23:17:19

标签: reactjs layout react-router-v4

我的App.js中有以下代码,下面是我的解释


      <Router>
        <Provider store={store}>
          <Fragment>
            <Switch>
              <Suspense fallback={<Loader />} maxDuration={5000}>


                <Layout> //This is the Layout wrapper
                  <PrivateRoute
                    exact
                    path="/en/account/dashboard"
                    component={Home}
                  />
                  <PrivateRoute
                    exact
                    path="/en/books"
                    component={Books}
                  />
                  <PrivateRoute
                    exact
                    path="/en/account/quiz"
                    component={Quiz}
                  />

                  <PrivateRoute
                    exact
                    path="/en/account/quiz/:slug/result"
                    component={QuizResult}
                  />

                  <PrivateRoute
                    exact
                    path="/en/account/my-books"
                    component={MyBooks}
                  />
                </Layout>


                <PrivateRoute
                  exact
                  path="/en/account/quiz/:slug"
                  component={QuizDetail}
                />
                <PrivateRoute
                  exact
                  path="/en/account/logout"
                  component={Logout}
                />
                <RedirectRoute exact path="/en/register" component={Register} />
                <RedirectRoute exact path="/en/login" component={Login} />
              </Suspense>
              <Route component={NoMatch} />
            </Switch>
          </Fragment>
        </Provider>
      </Router>

当我在其他任何路线上时,我都希望布局包装器不显示,即如果我要登录,注册,/ en / account / quiz /:slug或注销,则布局不应显示。 我该如何实现?

1 个答案:

答案 0 :(得分:0)

您为什么不将baselist=[] for x in range(len(df)): if (x % 2) == 0: newdf = df.iloc[x].append(df.iloc[x+1]) baselist.append(newdf) 写为高阶组件?

类似的东西:

Layout.jsx

Layout

然后在您的路由器中执行:

export default (Component) => (
  <Layout>
    <Component />
  </Layout>
)

那样<PrivateRoute path="/en/account/dashboard" component={Layout(Home)} /> 将仅在您想要的路线中显示。