背景:

1. 创建react项目icon-default.png?t=M5H6https://zh-hans.reactjs.org/docs/create-a-new-react-app.html#create-react-app

2. 建立react 路由icon-default.png?t=M5H6https://reactrouter.com/docs/en/v6/getting-started/overview

3. 使用ant designicon-default.png?t=M5H6https://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怎么实现页面组件跳转

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐