简体   繁体   English

我如何在reactjs中的路由中获取ID

[英]How can I get the id in routes in reactjs

I have to insert 2 id in my route and I have to insert those two in my database however the first path.id is undefined 我必须在路线中插入2个id,并且必须在数据库中插入这两个id,但是第一个path.id是未定义的

在此处输入图片说明

The path.id here is undefined 这里的path.id是未定义的

const {params} = this.context.router;
    const {router} = this.context;
    const {routes} = router;
    let {path} = routes[routes.length - 1];
    let {form} = this.props.timeline;

    form.TimelineKey = (params.id);
    form.Link = path.id+ "/" + params.id ;

I don't know how will I get the 1068. Here's how it happens in my debugger: 我不知道如何获得1068。这是在调试器中的过程:

在此处输入图片说明

All react-router parameters can be found under this.props.params . 所有react-router参数都可以在this.props.paramsthis.props.params

Based on the info provided in the comments, you can get the timeline parameter like this: 根据评论中提供的信息,您可以获取以下timeline参数:

this.props.params.timeline

So you can do: 因此,您可以执行以下操作:

form.Link = this.props.params.timeline + "/" + this.context.router.id ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM