【发布时间】:2021-03-01 14:20:06
【问题描述】:
我正在研究反应,我刚刚创建了项目以打印用户的历史路径。 代码如下:
return (
<div className="container">
<Row>
<Col>
<Nav
activeKey="/home"
className="history-path"
>
<div>you are here:</div>
<Nav.Item>
<Nav.Link href="/home" onSelect={() => history.push("/home", { from: "2" })}>Home</Nav.Link>
</Nav.Item>
<span>/</span>
<Nav.Item>
<Nav.Link href="/labour_desc" onSelect={() => history.push("/labour_desc", { from: "2" })} disabled>Description</Nav.Link>
</Nav.Item>
</Nav>
</div>
)
现在,我每次都在复制和粘贴导航并添加新链接。 例如,在下一页中,导航将是:
<Nav
activeKey="/home"
className="history-path"
>
<div>you are here:</div>
<Nav.Item>
<Nav.Link href="/home" onSelect={() => history.push("/home", { from: "2" })}>Home</Nav.Link>
</Nav.Item>
<span>/</span>
<Nav.Item>
<Nav.Link href="/labour_desc" onSelect={() =>
history.push("/labour_desc", { from: "2" })} disabled>Description</Nav.Link>
</Nav.Item>
<span>/</span>
<Nav.Item>
<Nav.Link href="/new_desc" onSelect={() =>
history.push("/new_desc", { from: "CreateDescription" })}
disabled>Create Description</Nav.Link>
</Nav.Item>
</Nav>
我不知道如何创建组件以仅传递新的 Nav.Item。 有什么帮助吗?
【问题讨论】:
-
hmmm....你能详细说明一下吗?并更新问题。我不明白你在复制粘贴什么以及为什么
-
对不起@ReyYoung,我现在正在做
-
无需抱歉。很酷。
-
@ReyYoung 我已经修改了问题,我希望现在会更清楚
标签: html css reactjs react-native