当我需要将用户重定向到另一个页面并在该页面上打开模式时,我使用以下方法:
var qsData = parseQueryString();
var showModal = ("show-modal" in qsData);
if (showModal) {
// Load the modal and change the url back to the base url
var modalToDisplay = qsData['show-modal'];
$(`a[data-modal-body-id="${modalToDisplay}"]`).click();
window.history.pushState({}, null, window.location.href.split('?')[0]);
}
这样,我可以传递一个网址,例如:
它将为他们打开“更改密码”模式。在执行此重定向时,我需要完成两件事:
实现此目标的最佳方法是什么?也就是说,更改url但不将其存储在历史记录中吗?我当时在考虑使用会话变量,但我认为这不起作用,因为有时url链接会出现在电子邮件中,因此有时我没有'state'开头。
答案 0 :(得分:1)
您应该尝试使用
window.history.replaceState({}, null, window.location.href.split('?')[0]);
这不会将新状态添加到堆栈中。它将替换当前版本。