M
M
Maxim Korolsky2017-05-25 20:39:01
React
Maxim Korolsky, 2017-05-25 20:39:01

How to create multiple layouts with React Router 4 (react-router-dom)?

Can't create 2 different Layouts in new version of React-Router
Help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Korolsky, 2017-05-26
@SuperPosan

Thanks everyone
The solution is:

<Switch>
                <Layout exact path="/properties" component={Properties} />
                <Layout path="/properties/:id" component={Property} />
              </Switch>


const Layout = ({component: Component, ...rest}) => {
  return (
    <Route {...rest} render={matchProps => (
      <div className="container-fluid flex-wrap justify-content-center d-flex layout flex-column" style={{ minHeight: '100vh', background: rest.white ? 'white' : '#eceff1' }}>

          <Header />
          <div style={{ flex: 1 }}>
            <Component {...matchProps} />
          </div>
          <Footer />

      </div>

    )} />
  )
};

export default Layout;

Respectively for other routes we create Layout in the same way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question