1、使用 react-router-dom 中的 Link 实现页面跳转
一般适用于,点击按钮或其他组件进行页面跳转,具体使用方式如下:
<Link
to={
{
pathname: '/path/newpath',
state: { // 页面跳转要传递的数据,如下
data1: {},
data2: []
},
}}
>
<Button>
点击跳转
</Button>
</Link>
2、使用 react-router-redux 中的 push 进行页面跳转
react-router-redux 中包含以下几个函数,一般会结合redux使用:
- push - 跳转到指定路径
- replace - 替换历史记录中的当前位置
- go - 在历史记录中向后或向前移动相对数量的位置
- goForward - 向前移动一个位置。相当于go(1)
- goBack - 向后移动一个位置。相当于go(-1)
具体使用时通过发送disppatch来进行页面跳转:
// 传递的参数
let param1 = {}
dispatch(push("/path/newpath'", param1));
dispatch(replace("/path/newpath'", param1));