React Router v4 with multiple layouts

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

    I don't think layouts belong in the route files.

    Keep the route clean, ie:

    
    

    Then, in the HomePage component, wrap the rendered content in your layout of choice:

    ...
    render() {
      
        

    Home page!

    }

    This way the routes remain super clean, plus you have an easy way to display routes which should support both layouts (404 pages for instance).

提交回复
热议问题