Javascript 通过<;传递道具中的行值;链接>;到新选项卡
在我的React应用程序中,当单击引导表中的一行时,我需要将值,Javascript 通过<;传递道具中的行值;链接>;到新选项卡,javascript,reactjs,react-router,react-props,Javascript,Reactjs,React Router,React Props,在我的React应用程序中,当单击引导表中的一行时,我需要将值,row.testid传递到后面的新选项卡 我了解到值不能在状态中传递。我们可以使用本地存储来传递变量吗?或者,有没有其他方法来传递它 column1=(单元格,行)=>{ let link=`${cell}` 返回( {cell} } 渲染部分 ========= 返回( ....... ); 请使用反应路由器的带路由器 <Link to={`/test/${row.testid}`} target="_blank&
row.testid
传递到后面的新选项卡
我了解到值不能在状态中传递。我们可以使用本地存储来传递变量吗?或者,有没有其他方法来传递它
column1=(单元格,行)=>{
let link=`${cell}`
返回(
{cell}
}
渲染部分
=========
返回(
.......
);
请使用反应路由器的带路由器
<Link to={`/test/${row.testid}`} target="_blank" rel='noopener noreferrer' >
{cell}
</Link>
{cell}
在testcomp中,您可以使用props.match.params获取参数
请将react路由器作为HOC使用
从“react router”导入{withRouter}
使用路由器导出默认值(testcomp)
this.props.match.params.rowid
更新:
<Route exact path="/test/:id" component={testcomp} />
// path match.params.id will depends on path params of /test/:params
//path match.params.id将取决于/test/:params的路径参数
如果在路线中使用id,请使用此.props.match.params.id。
例如,如果您使用path=“/test/:id”那么就使用params.id,如果您使用path=“/test/:rowid”那么就使用params.rowid最后我的代码工作了,将代码更改为{{pathname:
/test/${row.testid}
}-->/test/${row.testid} 谢谢大家的帮助 更新代码: 列1=(单元格,行)=>{ let link=
${cell}
返回(
}}target=“\u blank”rel='noopener noreferrer'>
{cell}
}
渲染部分
返回(
.......
)您好,我不能这样做,因为我需要模拟表数据。您能确认是否可以使用localstorage实现。如果可以,请提供任何示例代码。@shiju localstorage不是一个好方法,我建议使用**react router**,react router没有任何办法工作。我正在使用此方法,我知道您可以从matchUpda获取rowidted代码,以及下面Testcomp中的代码,从“react router”导入{withRouter};导出默认withRouter(Testcomp);是的,我这样做了。我们可以获取值(his.props.match.params.id)吗,在componentDidMount或构造函数方法中?@shiju您可以在componentDidMount和构造函数中获得参数值