[英]How to provide props to custom route in react-admin?
I'm using reac-admin, and want that after edit to redirect the user to custom route.我正在使用reac-admin,并希望在编辑后将用户重定向到自定义路由。
<Edit {...props}>
<TabbedForm redirect={redirect(`/XXX/${props.id}/YYY`)} >
{/* fileds */}
</TabbedForm >
</Edit>
in the custom routes I have this route:在自定义路线中,我有这条路线:
<Route exact path="/XXX/:id/YYY" render={(props) => <MyRoute {...props} />} />
My problem is how to pass props like in show?我的问题是如何像在节目中一样传递道具?
why when redirect to show: redirect="show"
, the props which are passed are different than when redirect to a custom route?为什么重定向到 show:
redirect="show"
时,传递的道具与重定向到自定义路由时不同?
There are missed props which I need them like the id.有一些缺少的道具,我需要它们,比如 id。
What sholud I do to solve my problem?我应该做什么来解决我的问题?
Thank you!谢谢!
You have two ways to do that:你有两种方法可以做到这一点:
<Route exact path="/XXX/:id/YYY" render={() => <MyRoute />} />
And inside MyRoute:在 MyRoute 内部:
import { useParams } from 'react-router';
const MyRoute = () => {
let { id } = useParams();
// ...
}
<Route exact path="/XXX/:id/YYY" render={(props) => <MyRoute id={props.match.params.id} />} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.