Multiple Layouts with React Router v4

后端 未结 4 1323
臣服心动
臣服心动 2020-12-13 23:12

I\'m pulling my hair out trying to render multiple layouts with React Router v4.

For instance, I\'d like pages with the following paths to have layout 1:

    <
4条回答
  •  轮回少年
    2020-12-13 23:27

    I know i am replying late but it's easy to do that, i hope it will helps to newbie. i am using React 4

    Layout.js

    export default props => (
        
    {props.children}
    );

    LoginLayout.js

    export default props => (
        
    {props.children}
    );

    Now finally we have our App

    App.js

    function renderWithLoginLayout(Component, Layout) {
        return 
    }
    
    function renderWithLayout(Path, Component, Layout) {
        return 
    }
    
    
    export default () => (
        
             renderWithLayout(this.path, Home, Layout)} />
             renderWithLayout(this.path, Counter, Layout)} />
             renderWithLayout(this.path, FetchData, Layout)} />
             renderWithLoginLayout(Login, LoginLayout)} />
        
    );
    

提交回复
热议问题