react-router跳转传值

来源:互联网 发布:双头螺纹怎么编程 编辑:程序博客网 时间:2024/06/05 07:47

跳转页面传递参数

1.引入包 
import {hashHistory} from ‘React-router’

2.跳转传值

复制代码
    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里面获取结果,当然也可以在组件里面获取结果

组件页面获取结果的写法为:

复制代码
import {hashHistory} from 'react-router';hashHistory.listen(location => {          //获取传递的数据,对象、值....                console.log(location.query);          // 获取路径        console.log(location.pathname);    }})
复制代码
原创粉丝点击