我在主要组件中有这个链接如何获取播放器组件中的值:
<Link to="/player" params={{ testvalue: "hello" }}
className="btn">watch</Link>
class Player extends React.Component{
render(){
alert(this.params.testvalue);
return(
<div></div>
);
}
}
这是路线档案
<Route path="/" component={App}>
<IndexRoute component={main}/>
<Route path="/player" component={Player}/>
</Route>
答案 0 :(得分:0)
使用react路由器将位置对象作为props传递下来,应该能够使用
访问查询 this.props.params.testvalue
答案 1 :(得分:0)
您的代码存在的问题是您使用
传递参数<Route path="/" component={App}>
<IndexRoute component={main}/>
<Route path="/player/:value" component={Player}/>
</Route>
但你没有在路线上收到它。像
一样改变你的路线this.props.params.testvalue
然后使用
{{1}}播放器组件中的
。