问题描述
我有一个 Dasboard 组件,其中我有 React-router <Link/>
组件链接到
http:<procjethos>/team
在<Team/>
组件中,我有一个<Link/>
组件应该链接到
http:<projecthost>/list/:listId
但相反,它继承自上一个链接,我得到
http<projecthost>/team/list/:listId
// 仪表板.jsx
render() {
const { shoppingLists, teams } = this.props;
return (
<Fragment>
<Toolbar isHomePage/>
<div className="wrapper">
<div className="dashboard">
<h2 className="dashboard__heading">
<TeamIcon />
Cohorts
</h2>
<ul className="dashboard__list">
{_map(teams, team => (
<li className="dashboard__list-item" key={team._id}>
<Link to={`team/${team._id}`}>
<CardItem name={team.name} />
</Link>
</li>
))}
</ul>
</div>
</div>
</Fragment>
);
// 团队.jsx
<Fragment>
<Toolbar />
<div>
Cohort of id:
{id}
<ul>
{_map(lists, list => (
<li className="dashboard__list-item" key={list._id}>
<Link to={`list/${list._id}`} replace>
<CardItem name={list.name} />
</Link>
</li>
))}
</ul>
</div>
</Fragment>
如何使用嵌套链接在 React-Router 4 中实现所需的行为?
1楼
Shubham Khatri
1
已采纳
2019-02-21 09:19:02
在链接路径前添加/
<Link to={`/list/${list._id}`} replace>
<CardItem name={list.name} />
</Link>