this.props.history.push 传参数 url、state 混合传参

1. url 传参

一般跳转传递 id 都放入 url 中

this.props.history.push(`/document-analysis/fans-list?id=${this.state.bloggerId}`)

地址栏显示

在这里插入图片描述
在跳转接收页 this.props.location 打印的路由参数

在这里插入图片描述

2. state 传参

跳转时需要带其他较多数据,无法在 url 上携带,可以使用 state 传值

this.props.history.push({ 
	pathname: `/document-analysis/concern-list`, 
	state:this.state.bloggerId 
})

地址栏显示

在这里插入图片描述
在跳转接收页 this.props.location 打印的路由参数

在这里插入图片描述

3. url、state 混合传参

当有 id 要在 url 中显示,又有较多其他数据携带时,可以使用混合传参

this.props.history.push({ 
	pathname: `/document-analysis/concern-list`, 
	search: this.state.bloggerId, 
	state:this.state.bloggerId 
})

地址栏显示
在这里插入图片描述
在跳转接收页 this.props.location 打印的路由参数

在这里插入图片描述
search 属性会在 pathname 属性填写的路径后默认补 一个问号,需要显示在地址栏的信息可以写在 search 属性中

this.props.history.push({ 
	pathname: `/document-analysis/concern-list`, 
	search: `id=${this.state.bloggerId}`, 
	state:this.state.bloggerId 
})

地址栏显示

在这里插入图片描述
在跳转接收页 this.props.location 打印的路由参数

在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值