React-router:更改 URL 并清除历史记录 [英] React-router: Change URL and clear history

查看:38
本文介绍了React-router:更改 URL 并清除历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下场景:

用户打开激活链接;用户完成激活过程后,系统会将其移至另一个页面.
我不想在浏览器的历史记录中保留激活链接,因为当用户返回时,他们将再次进入激活步骤.

A user opens an activation link; after the user has completed the activation process, the system will move them to another page.
I don't want to keep the activation link in the browser's history because when the the user goes back they will get to the activation step again.

如何替换浏览器的历史记录以从我的应用程序中删除某些请求?

推荐答案

ReactJs 中,您应该为此使用 browserHistory.这会处理您的历史记录,您无需自行实现这些功能.

In ReactJs you should use browserHistory for this purpose. This takes care of your histories and you don't need to implement those functions on your own.

browserHistory 有 2 个方法 push()replace(),它们的功能与 @fazal 在他的回答中提到的功能相同,但方式更好.

browserHistory has 2 methods push() and replace() which do the same functions as @fazal mentioned in his answer but in a better way.

所以如果你想避免用户回到以前的状态,你需要使用 browserHistory().replace

So if you want to avoid user going back to previous state you would need to use browserHistory().replace

首先将其导入到您的代码中:

Start with importing it into your code:

import {browserHistory} from 'react-router'

用户激活后,您执行以下操作:-

After user has activated you do following:-

browserHistory.replace(//your new link)

这篇关于React-router:更改 URL 并清除历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆