React Router 5 路由跳转

2022/01/11 posted in  React Router
Tags:  #React

Link 路由跳转

  1. Link 组件默认为 push 模式,点击时会在 history 增加链接记录,后退能返回先前链接
  2. 加入 replace 可切换为 replace 模式,点击时会替换当前 history 链接记录,不能通过后退返回先前链接

编程式路由跳转

路由组件

replace 方式

push 方式

后退一步

前进一步

前进或后退 n 步,正数前进,负数后退

一般组件

路由组件自带 history 对象,能用 API 进行跳转,而一般组件没有 history 对象。使用 withRouter 可以使一般组件也具有 history 对象。