简体   繁体   English

带标签的动态反应路由器

[英]Dynamic React Router with Tabs

I have a page with a table, where you click on a <tr> and the user is redirected to another page, like this:我有一个带有表格的页面,您可以在其中单击<tr>并将用户重定向到另一个页面,如下所示:

// parent component
<tr onClick={() => this.props.history.push(`users/${id}`)}>

At the new page called users, there are two tabs which also redirect to other pages:在名为 users 的新页面上,有两个选项卡也重定向到其他页面:

// users page receives the id from the parent 
// component with this.props.history.push()
<Tab label='Users' key='users'>
    <div>users page content</div>
</Tab>

// This page must also receive the id from parent component. 
// The structure is similar to users page.
<Tab label='Info' key='info'>
    <Redirect to={'/info/:id'} />
</Tab>

So, I need to pass the id from the parent page to [info page/tab 2] and redirect from [info page/tab 2] to [users/tab 1] at will with the id from parent, something like this:因此,我需要将 id 从父页面传递到 [info page/tab 2] 并从 [info page/tab 2] 重定向到 [users/tab 1],使用来自父页面的 id,如下所示:

[tab 1]: users/12345
[tab 2]: info/12345

How can I achieve this result?我怎样才能达到这个结果? Thank you!谢谢! :) :)

If you define your Routes like如果你定义你的路线

/users/:userId
/info/:userId

You can read the userID from params and use that to navigate between pages您可以从 params 读取用户 ID 并使用它在页面之间导航

<Tab label='Info' key='info'>
    <Redirect to={`/info/${this.match.params.userId}`} />
</Tab>

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

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