加入代码中有这样一个路由需要渲染;
render(
, ele)
但是App组件是这样的;
import React ,{ Component }from 'react';
import Nav from './nav';
import Foot from './foot';
class App extends Component{
constructor(props){
super(props);
}
render(){
return (
{this.props.name}
{this.props.children}
)
}
}
export default App;
App组件中这个 {this.props.name}是通过外面参数传递进来的,但是上面的代码中怎么向App传递参数呢;
如果是单纯的渲染App可以这样写:
render(
, ele)
希望有知道的朋友帮忙解答一下啊
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
讲道理。react-router 封装的这些组件,是不允许你自定义传props的。只支持那几个固定的,比如history,
params,location,route等等,都是跟路径参数有关的。
如果想传一些自定义的数据,可以结合redux,直接connect往组件里传store。。
因为你直接给Router或者Route穿props 其实是给了Router组件,它不会帮你做注入props。
可以自己尝试封装一层。- -
还是用react-redux吧...
是路由向组件传参吗?
<Route path="/job/:id" component={jobDetail} />
jobDetail组件就能渠道路由中的ID了,通过this.props.params.id
可以参考下阮一峰的React Router,http://www.ruanyifeng.com/blo...
如果你用了react-router的话
在配置路由路径的时候可以这样写
path=yourroutername/:id在你的组件里就可以这样调用
我上面写的我需要的id就可以这样获得
let myId=this.props.params.id这个id的名字和上面path是对应的