📜  × 错误:不变量失败:您不应该使用<Switch>外面<Router>- Javascript代码示例

📅  最后修改于: 2022-03-11 15:02:47.533000             🧑  作者: Mango

代码示例1
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