React-Router only one child

后端 未结 10 1740
执笔经年
执笔经年 2020-12-07 14:32

I keep on getting the error:

A \'Router\' may have only one child element

when using react-router.

I can\'t seem to fig

10条回答
  •  不思量自难忘°
    2020-12-07 15:15

    This is an API change in react-router 4.x. Recommended approach is to wrap Routes in a Switch: https://github.com/ReactTraining/react-router/issues/4131#issuecomment-274171357

    Quoting:

    Convert

    
      
      
    
    

    to

    
      
        
        
      
    
    

    You will, of course, need to add Switch to your imports:

    import { Switch, Router, Route } from 'react-router'
    

提交回复
热议问题