React Router v4 with multiple layouts

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

    Update: I solved it another way, but if forces you to namespace the different parts of your app with /app or /admin for example.

    Each of the components UserRoutes, AdminRoutes and PublicRoutes are basically large Switch components with the specific layout at its root.

    Here's how it looks:

    
      
         } />
         } />
         } />
      
    
    

    Old: One solution would be to use the render prop of each Route, but it seems really cumbersome:

    
      
         }
        />
         }
        />
         }
        />
         }
        />
      
    
    

提交回复
热议问题