Created
          August 8, 2017 11:54 
        
      - 
      
 - 
        
Save avinmathew/e82fe7e757b20cb337d5219e0ab8dc2c to your computer and use it in GitHub Desktop.  
    Multiple layouts with React Router v4
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import React from "react" | |
| import { Route, Switch } from "react-router-dom" | |
| const AppRoute = ({ component: Component, layout: Layout, ...rest }) => ( | |
| <Route {...rest} render={props => ( | |
| <Layout> | |
| <Component {...props} /> | |
| </Layout> | |
| )} /> | |
| ) | |
| const MainLayout = props => ( | |
| <div> | |
| <h1>Main</h1> | |
| {props.children} | |
| </div> | |
| ) | |
| const AltLayout = props => ( | |
| <div> | |
| <h1>Alt</h1> | |
| {props.children} | |
| </div> | |
| ) | |
| const Foo = () => ( | |
| <p>Foo</p> | |
| ) | |
| const Bar = () => ( | |
| <p>Bar</p> | |
| ) | |
| const App = () => ( | |
| <div> | |
| <Switch> | |
| <AppRoute exact path="/foo" layout={MainLayout} component={Foo} /> | |
| <AppRoute exact path="/bar" layout={AltLayout} component={Bar} /> | |
| </Switch> | |
| </div> | |
| ) | 
This would cause unnecessary rerendering in every client side navigation
This would cause unnecessary rerendering in every client side navigation
@aiveneh do you have any idea how we can prevent rerendering
This was really useful to me. it saved my day
Thank you, this is cool!
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Very usefull thanks