在使用Link組件跳轉頁面時有兩種頁面跳轉,分別爲:
1、在當前標籤頁頁面跳轉
2、跳轉到新的標籤頁
一、在當前標籤頁中路由跳轉
代碼如下:
const { voucherType,organizationId } = record;
<Link to={{pathname:'/voucher/voucherSummary/voucherSummaryDetail', query:{voucherType,organizationId}}}>查看</Link>
如何獲取query中的傳值,在這裏需要用到location,location下面會帶有query對象,裏面就是傳過來的值:
const {
location:{
query:{ voucherType,organizationId }
}
} = this.props;
第一種形式直接使用Link組件的to屬性,pathname的值就是在router.config.js中定義的要跳轉頁面的路由,比如我的router.config.js中定義的路由爲:
{
path: '/voucher/voucherSummary/voucherSummaryDetail', //調用此處的路徑,就會自動調用component屬性下的組件中
name: 'voucherSummaryDetail',
hideInMenu: true,
component: './Voucher/VoucherSummary/VoucherSummaryDetail', //組件
},
二、跳轉到新的標籤頁
與第一種不同的是,這時我們傳參不用query屬性,而是需要使用url地址傳參,就像get的請求方式,因爲這樣才能將參數帶到新的標籤頁中:
const { voucherType, organizationId, actionId } = record;
<Link to={`/voucher/voucherSummary/voucherSummaryDetail?voucherType=${voucherType}&organizationId=${organizationId}&actionId=${actionId} `} target='_blank'>查看</Link>
取值方式與第一種傳參取值方式相同:
const {
location:{
query:{ voucherType,organizationId }
}
} = this.props;
跳轉之前的url(路徑末尾的 /list 爲重定向時定義的值,請忽略不計):
跳轉到新頁面的url:
在項目中常用的路由傳值就是以上兩種方式了,我相信路由傳值方式不止以上兩種,若大家使用的是其他的傳值方式可以留言,我也去研究研究,共勉。