react-router 学习笔记之Link带参数传值
来源:互联网 发布:sas数据分析大赛题目 编辑:程序博客网 时间:2024/06/15 02:47
1、通过to='xx/xx'直接条状<Link to={`/my/${myId}/info}>点击</Link>
2、to=对象,带参数跳转(pathname, query, hash, state(额外数据)),注意:这些参数都被存放到this.props.location中
<li><Link to={{pathname:"/select", hash:'#ahash', query:{foo: 'bar', boo:'boz'}, state:{data:'miao'} }} activeClassName="GlobalNav-active">精选</Link></li>
3、to=函数,注册到路由跳转事件中,每一次路由变化,都会执行该函数,并经最新的location作为参数,
<Link to={location => ({ ...location, query: { name: 'ryan' } })}>
Hello
</Link>
4、不使用Link,在函数内直接操作router
旧版本:由于router只用的context传递路由信息,因此每一个组件都可以轻易的通过this.context.router获取路由
新版本:router被放置在this.props中,通过this.props.router可以获取路由
注意:push与replace的区别,一个是添加,一个是替换,历史记录中被替换的已经不存在了,所以浏览器回退不到替换前的页面。
changeRouter = () => {
console.log(this.props)
// this.props.router.push('/follow');
// this.props.router.push({
// pathname:'/follow',
// state:{name:'xxx'},
// query: {foo: 'bar'}
// })
// this.props.router.replace('/follow');
this.props.router.replace({
pathname: '/follow',
query: {foo:'bar'}
})
}
复制代码
- react-router 学习笔记之Link带参数传值
- react-router 学习笔记之Link带参数传值
- react-router带参数使用Link跳转并取出参数
- react-router学习笔记之入门
- react-router学习笔记之入门
- react-router学习笔记
- react-router 学习笔记
- react-router 学习笔记
- react-router 学习笔记
- React-Router 学习笔记
- react-router 学习笔记
- react-router 学习笔记
- React-Router 学习笔记
- react-router学习笔记
- react-router-dom 通过Link传值的坑人表现!
- React笔记(一):react-router跳转传值
- React 之 react-router
- react-router 4.2.0<link>页面跳转-传参与不传参
- linux下安装nginx
- 清除浮动的影响的方法
- SQL中使用where 1=1 和 select * 的坏处
- 让测试/开发/生产环境相分离
- 无言
- react-router 学习笔记之Link带参数传值
- jq 多个《button》 点击事件(含 ajax ,action), 功能版
- TabLayout——浅谈
- mysql 数据库迁移
- 生成对抗网络(GAN)的前沿进展(论文、报告、框架和Github资源)汇总
- 区间更新 区间和查询 带有延迟标记 线段树 hdu1698; 附:csa 区间加值,维护最大值
- 程序员学习网址 (持续更新)
- pomelo源码解析之组件Remote
- jdk源码学习笔记---Integer