React Router v4 with multiple layouts

前端 未结 12 1612
旧时难觅i
旧时难觅i 2020-12-13 00:08

I\'d like to render some of my routes within my public layout, and some other routes within my private layout, is there a clean way to do this?

Example that obviousl

12条回答
  •  执念已碎
    2020-12-13 00:44

    What I have done for this is create a simple component that adds an extra property to the Route component which is layout:

    function RouteWithLayout({layout, component, ...rest}){
      return (
        
          React.createElement( layout, props, React.createElement(component, props))
        }/>
      );
    }
    

    Then in your case your routes would look like this

    
        
        
        
        
    
    

提交回复
热议问题