一、取url上的参数
1、this.props.location.search得到url上的数据
2、split方法根据? = 将字符串变为数组,然后取自己想要的数据
3.url跳转时候使用,编码用encodeURI,解码用decodeURI。得到数据
const query = decodeURI(this.props.location.search.split('?')[1].split('=')[1])
二、动态路由参数界面进行跳转,在分类界面想点击进入详情页,于是写了下面这些
this.props.history.push('detailed/' + id)
但是发现不会进行跳转而是接上去
http://localhost:3000/#/sort/detailed/99776
然后在匹配页面这加上一个斜杆
this.props.history.push('/detailed/' + id)
才能够替换掉sort
http://localhost:3000/#/detailed/99776
加上斜杠,浏览器就会将你视作跳转界面而不是添加动态参数