react-router-app Redirect 报错You tried to redirect to the same route you're currently on:xxx

我们写了一个 react路由重定向 当时根路由时自动重定向到登录
下面的写法执行是 是可以执行的但是会报出一个错误
You tried to redirect to the same route you’re currently on:login

<Route  path='/'>
	<Redirect  to="/login"  />
</Route>

解决上面这个报错
通过 Route 内联 render函数

<Route exact path='/' render={()=>(<Redirect to='/login' />)} />

猜你喜欢

转载自blog.csdn.net/weixin_38644883/article/details/85773579