在react中使用Switch时,出现了报错
Warning: React does not recognize the computedMatch prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase computedmatch instead. If you accidentally passed it from a parent component, remove it from the DOM element.
引起警告的原因是: 在react-router-dom的<Switch>中使用了<div>,不要将组件的属性, 传给DOM节点。
例如:
<Router>
<Switch>
<div className="App">
<Route exact path="/"> <Home /> </Route>
<Route path="/hot"> <Hot /> </Route>
<Route path="/about"> <About /></Route>
<Route path="/collocation"><Collocation /></Route>
</div>
</Switch>
</Router>
就会出现报错,一个解决的方法是,将Switch写在到div的里面
<Router>
<div className="App">
<Switch>
<Route exact path="/"> <Home /> </Route>
<Route path="/hot"> <Hot /> </Route>
<Route path="/about"> <About /></Route>
<Route path="/collocation"><Collocation /></Route>
</Switch>
</div>
</Router>