[英]Route loading or mounting twice in React Router
当应用程序启动时,路由被挂载/加载两次。
这是显示该问题的视频: https://imgur.com/1nwZS4O
这是我的代码:
<Router history={props.history}>
<Switch>
<Route exact path="/" render={() => <Redirect to="/event/1234" />} />
{/*Event */}
<Route exact path="/event/:eventId" component={Event} />
<Route exact path="/event/:eventId/friends" component={Friends} />
<Route component={NotFound} />
</Switch>
</Router>
知道如何解决吗? 请帮忙
沙盒: https://codesandbox.io/s/keen-silence-47ztr?file=/src/App.js:528-884
注意:您无法在移动设备上重现该问题。
好吧,您正在代码中进行重定向
if (!!matches) {
const defaultPathname = `/event/${matches[1]}`;
props.history.replace(defaultPathname); // redirect here
}
在您的视频中,您正在调用https://47ztr.csb.app/event/1234/friends
重定向到https://47ztr.csb.app/event/1234/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.