React Router 链接到新选项卡

Bou*_*Bou 2 javascript reactjs react-router

我正在尝试使用 React Router 在新选项卡中渲染新组件。它有一个正在传递的参数。

下面是在同一选项卡中使用一个参数对我有用的示例。如果我将 target="_blank" 添加到下面的链接,则会收到 404 错误。

index.js 中的路由:

<Route exact path="/a-graph/:anId" component={aGraph} />
Run Code Online (Sandbox Code Playgroud)

主菜单页面链接:

<Link to={"/a-graph/anId"} style={{ overflowX: "visible", color: "black" }}>
    <MenuItem fitted key="graph" text="A Graph"/>
</Link>
Run Code Online (Sandbox Code Playgroud)

我需要更改什么才能在新选项卡中使用参数打开此组件?谢谢!

编辑:我的 URL 显示为 /a-graph/anId 这是一个数字。如果我的路线和链接正确,我不知道如何得到 404。感谢您的关注!

TKo*_*KoL 5

<Link target="_blank" to={"/a-graph/anId"} style={{ overflowX: "visible", color: "black" }}>
    <MenuItem fitted key="graph" text="A Graph"/>
</Link>
Run Code Online (Sandbox Code Playgroud)

如下所示:https: //github.com/ReactTraining/react-router/issues/2188#issuecomment-146366561

在 1.0 中这是支持的。我们只是将您提供给元素的所有额外道具传递<Link>给该<a>元素。所以,<Link ... target="_blank">会如你所期望的那样工作。