Using multiple layouts for react-router components

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

If I have the following:



  { /* Routes that use layout 1 */ }
  

        
6条回答
  •  时光说笑
    2020-12-14 09:46

    You could create a function RouteWithLayout that renders the wrapped within the layout:

    const RouteWithLayout = ({ component: Component, layout: Layout, ...rest }) => (
       (
        
          
        
      )} />
    )
    
    const MainLayout = props => (
      

    Main

    {props.children}
    ) const AltLayout = props => (

    Alt

    {props.children}
    ) const Foo = () => (

    Foo

    ) const Bar = () => (

    Bar

    ) const App = () => (
    )

提交回复
热议问题