背景:
1. 创建react项目 https://zh-hans.reactjs.org/docs/create-a-new-react-app.html#create-react-app
2.?建立react 路由 https://reactrouter.com/docs/en/v6/getting-started/overview
3. 使用ant design https://ant.design/components/overview-cn/
在写完登录注册之后,需要跳转到主页面
使用 react-router-redux 中的 push 进行页面跳转加刷新页面:
- push - 跳转到指定路径
- replace - 替换历史记录中的当前位置
- go - 在历史记录中向后或向前移动相对数量的位置
- goForward - 向前移动一个位置。相当于go(1)
- goBack - 向后移动一个位置。相当于go(-1)
一:在自定义路由的文件夹下新建一个history.js
import { createBrowserHistory } from 'history'
export default createBrowserHistory();
在登录的js文件里设置:
import history from "history.js的路径";
// 使用history进行跳转
history.replace({ pathname: "目标路由路径", state: {} });
history.go(0);
?相关资源:react怎么实现页面组件跳转
|