react 设置重定向时报错 You tried to redirect to the same route you're currently on: "/home"
代码截图如下所示
回答
筱竹回答
1、问题分析
报错信息为:你试图重定向到你当前的路线:“/home”,也就是意味着,你当前的路由就是 /home,然后又重定向到了 /home 这个路由,所以会报此错误。
2、解决问题办法
在三元表达式中的 <Route path="/" render={……} /> 的外边嵌套一个 <Switch></Switch> 标签,
如下所示:
window.location.hash.split("/")[1] ? ' ' : <Switch><Route path="/" render={……} /></Switch>
(0)
相似问题