方法一
1.引入Link模塊
import { Link } from 'dva/router';
2.Link標(biāo)簽中帶上要傳遞的參數(shù)
<Link to={
{
pathname:`/要跳轉(zhuǎn)的路徑`,
state:{key值:val值}
}
}>
3.在跳轉(zhuǎn)頁(yè)面接收
componentWillMount(){
//console.log(this.props.location)//傳遞過(guò)來(lái)的所有參數(shù)
console.log(this.props.location.state.key值)//val值
}
方法二
1.引入包
import {hashHistory} from ‘React-router’
2.跳轉(zhuǎn)傳值
handleClick = (value) => {
hashHistory.push({
pathname: 'message/detailMessage',
query: {
title:value.title,
time:value.time,
text:value.text
},
})
}
3.接收值
console.info(this.props.location.query.title)
console.info(this.props.location.query.time)
console.info(this.props.location.query.text)
4.如果使用的ant design收厨,可以在model里面獲取結(jié)果愿卸,當(dāng)然也可以在組件里面獲取結(jié)果
組件頁(yè)面獲取結(jié)果的寫法為:
import {hashHistory} from 'react-router';
hashHistory.listen(location => {
//獲取傳遞的數(shù)據(jù),對(duì)象斤葱、值....
console.log(location.query);
// 獲取路徑
console.log(location.pathname);
}
})