React Router v4 with multiple layouts

前端 未结 12 1622
旧时难觅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:39

    Use the render prop of Route component, this will not unmount and mount your layout component on every route change. More details of how this works here.

    Say you have two layout components Primary.js and Secondary.js

    In your App.js render method, you simply return

    
       
          } />
          } />
       
    
    

    To refine it further, you can also define a Higher order component layout component to wrap your page component with a layout. (Not tested)

     Secondary(Login)}
    

提交回复
热议问题