Warning: You tried to redirect to the same route you're currently on: "/home"


react-router-dom 版本4.3.1 配置路由
  
 
 出错代码:
  
import {Route, Switch} from 'react-router-dom'
 import { Redirect} from 'react-router'
1 <Redirect from="/" to="/home" />
2 <Route exact path="/login" component={Login}/>
3                 
4 <Home>
5   <Route path="/model" component={Model}/>
6    <Route path="/result" component={Result}/>
7 </Home>

解决方法: 

import {Route, Switch} from 'react-router-dom'
import { Redirect} from 'react-router'
<Switch> <Route exact path="/login" component={Login}/> <Home> <Route path="/model" component={Model}/> <Route path="/result" component={Result}/> </Home> <Redirect from="/" to="/home" /> </Switch>
Switch标签包裹Route,讲Redirect放到最后,解决


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM