react-router跳转传值

跳转页面传递参数

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);
    }
})