Invariant Violation: You should not use outside a

后端 未结 10 1420
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 00:30

I have a problem that I don\'t know how to solve, I get this error when running npm test

Invariant Violation: You should not use

10条回答
  •  长情又很酷
    2021-02-01 01:20

    The error is correct. You need to wrap the Switch with BrowserRouter or other alternatives like HashRouter, MemoryRouter. This is because BrowserRouter and alternatives are the common low-level interface for all router components and they make use of the HTML 5 history API, and you need this to navigate back and forth between your routes.

    Try doing this rather

    import { BrowserRouter, Switch, Route } from 'react-router-dom';
    

    And then wrap everything like this

    
     
      //your routes here
     
    
    

提交回复
热议问题