react小知识点集合

1:路由传递参数的两种形式

get 传值
<Link to={`/newsdetail?newid=${item.id}`}>{item.title}</Link>

接收
var search = this.props.location.search;

使用url库解析
npm install url --save
import url from 'url';
var search = this.props.location.search;
var newid = url.parse(search, true).query.newid;

-----------------------------------------------------------------

动态路由传值
<Route path="/newsdetail/:newid" component={NewsDetail}/>
<Link to={`/newsdetail/${item.id}`}>{item.title}</Link>

接收
var newid = this.props.match.params.newid;

猜你喜欢

转载自www.cnblogs.com/panrui1994/p/11841326.html