react-router实现前进后退的方法:1、通过“goback(){this.props.history.goback()}”实现路由前进;2、通过“go(){this.props.history.go(-1) }”实现路由回退。

本教程操作环境:windows10系统、react18版、dell g3电脑。
react-router怎么实现前进后退?
react-路由跳转方式与路由前进回退
1、标签跳转
//1.引入依赖
import { link } from 'react-router-dom'
//2.在需要的地方加上这段,link标签是a标签
2、事件跳转
//1.引入依赖
import { withrouter } from 'react-router-dom';
//2.比如使用点击事件
fun(){
this.props.history.push('/*你的路由*/')
}
export default withrouter (app);路由前进gobac()
goback(){
this.props.history.goback()
}路由回退push()
go(){
this.props.history.go(-1)
}
kop杰拉德