Using multiple layouts for react-router components

前端 未结 6 1579
执念已碎
执念已碎 2020-12-14 09:22

If I have the following:



  { /* Routes that use layout 1 */ }
  

        
6条回答
  •  渐次进展
    2020-12-14 09:57

    I came across this question and found a solution that I want to share.

    With react router v4 we could render the routes directly in your layout. Which is more readable and easy to maintain.

    Layout

    export class MainLayout extends React.PureComponent {
      render() {
        return (
          
    {this.props.children}
    ); } } Mainlayout.propTypes = { children: PropTypes.node.isRequired, }

    Router

    export default function App() {
      return (
        
          
            
              
              
            
          
          
            .... other paths
          
        
      );
    }
    

提交回复
热议问题