在 "domain.com/" 之后更改地址 URL 而不重新加载页面

Changins Address URL All Afer "domain.com/" Without Reloading Page

我的多级菜单片段


我的 PushState

我有一个完全可用的 PushState 变量,它将创建上面以粗体显示的部分,我希望 URL 显示的方式。

PushState = $(e.target).parentsUntil(".Menu").filter("li").children("a").map(function() {
                return $(this).find('span.Title').text().trim().replace(/&/g,"and").replace(/\s+/g, '-').replace(/Master-Dashboard/g,"Dashboard");
            }).get().reverse().join("/");

window.history.pushState(null, null, PushState);

我遇到的问题

在页面加载时,点击 Account > Dashboard,它确实将地址栏中的 URL 更改为 domain.com/Account/Dashboard,但是当点击 Workstation > Dashboard 时,地址栏中的 URL 更改为 domain.com/Account/Work-Station/Dashboard 并再次变回 returns domain.com/Account/Work-Station/Account/Dashboard


问题

在不重新加载页面并允许 bask/forward 功能的情况下,我如何才能更改 domain.com/ 之后的所有内容,而不是像当前所做的那样添加到最后一个 /

history.pushState({}, "","/"+ PushState); 
// passes an empty state, an empty string, and a full URL with the leading slash

你需要斜线来去掉之前的路径。