Skip to content

Commit 142ad75

Browse files
committed
don't push state with same url
Currently navigating through documentation sometimes leads to duplicate history entries, also when navigating back to documentation page either from another documentation page or from different site, pushState not only add additional entry, but also removes all history in front. Ensuring that pushState is done only if new url is not equal current resolves this. I see only one quirky downside - it is not possible to create multiple history entries by navigating to same documentation page.
1 parent 49d4d32 commit 142ad75

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/utils/common-utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ export function replaceState(rawElementId) {
151151
const newQuery = query.toString().length > 1 ? `${query.toString()}&route=${elementId}` : `route=${elementId}`;
152152

153153
const fragment = `#${currentNavigationHashPart}?${newQuery}`;
154-
const url = new URL(fragment, window.location.href);
155-
window.history.pushState(null, null, url.href);
154+
const currentHref = window.location.href;
155+
const url = new URL(fragment, currentHref);
156+
if (url.href !== currentHref) {
157+
window.history.pushState(null, null, url.href);
158+
}
156159
}
157160

158161
export function toMarkdown(markdownStringRaw) {

0 commit comments

Comments
 (0)