如何解决反应路由器程序重定向到具有多个参数的路由不起作用
我正在尝试通过具有两个动态参数的url将用户重定向回先前的路由。但是,添加这两个参数会使重定向成为无操作。
当我在没有他们的情况下重定向时,它可以正常工作。也可以通过url访问路由。它实际上似乎是程序重定向。我尝试过推送到历史记录堆栈,并使用Link div-无济于事。谁能将我推向正确的方向?
url:入职/ 5f4a3ee7e28892ae792a0107 / 5f4a3ee7e28892ae792a0105
goTo(redirectTo) {
this.setState({ redirectTo });
}
renderRedirect() {
const { redirectTo } = this.state
const path = `/${redirectTo}`;
if (!redirectTo) {
return;
}
return <Redirect to={path}/>
}
render() {
return (
<browserRouter>
{this.renderRedirect()}
<div
className={`App ${
window.location.pathname !== '/admin' ? 'view' : ''
}`}
>
<SchedulePanel />
<img className="voxpop-logo" src={VoxPoplogo} alt="logo" />
<Switch>
<Route
path="/onboarding/:eventId/:groupId"
exact
component={OnboardingView}
/>
<Route path="/profile" exact component={ProfileView} />
<Route
path="/questions"
exact
component={QuestionsView}
/>
<Route
path="/searching"
exact
component={SearchingView}
/>
<Route path="/match" exact component={MatchView} />
<Route path="/chat" exact component={ChatView} />
<Route
path="/offboarding"
exact
component={OffboardingView}
/>
<Route path="/admin" exact component={AdminView} />
<Route path="/no-match" exact component={NoMatch} />
<Route path="/dev" exact component={Dev}/>
</Switch>
</div>
</browserRouter>
);
}
解决方法
我注意到您在<Route />
路线的/onboarding/:eventId/:groupId
中,您拥有exact
道具。这可能是问题所在,因为根据docs,exact
上的<Route />
属性表示URL必须完全匹配 。当然,动态路径不会出现这种情况。
在没有exact
道具的情况下尝试一下,看看它是否可以解决!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。