React中,路由跳转的方法有很多,以下为您推荐:
1.使用react-router-dom中的Link实现页面跳转。一般适用于点击按钮或其他组件进行页面跳转,具体使用方式如下:
jsx
reactrouter6路由拦截<Link to={{pathname:'/path/newpath',state:{// 页面跳转要传递的数据,如下data1:{}, data2:[]},}}><Button>点击跳转</Button></Link>
2.使用react-router-redux中的push进行页面跳转。react-router-redux中包含以下几个函数,一般会结合redux使用:
1)push - 跳转到指定路径。
2)replace - 替换历史记录中的当前位置。
3)go - 在历史记录中向后或向前移动相对数量的位置。
4)goForward - 向前移动一个位置(相当于go(1))。
5)goBack - 向后移动一个位置。