Using multiple layouts for react-router components

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

If I have the following:



  { /* Routes that use layout 1 */ }
  

        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 10:00

    Route's path property has accepted an array of strings for a while now. See https://github.com/ReactTraining/react-router/pull/5889/commits/4b79b968389a5bda6141ac83c7118fba9c25ff05

    Simplified to match the question routes, but I have working multiple layouts essentially like this (using react-router 5):

    
      
        
          
            
              
              
            
          
        
        {/* Layout 1 is last because it is used for the root "/" and will be greedy */}
        
          
            
              
              
              
              
            
          
        
      
    
    

    This solution prevents re-mounting the layouts on route changes, which can break transitions, etc.

提交回复
热议问题