Skip to content

A platform for community discussion. Free, open, simple.

FIX: URL fragments not purging (#19324)

Penar Musaraj57fe57e7ce0a
diff --git a/app/assets/javascripts/discourse/app/lib/url.js b/app/assets/javascripts/discourse/app/lib/url.js
index 0bd9a28efbf..996a51f94dd 100644
--- a/app/assets/javascripts/discourse/app/lib/url.js
+++ b/app/assets/javascripts/discourse/app/lib/url.js
@@ -216,7 +216,7 @@ const DiscourseURL = EmberObject.extend({
const m = /^#(.+)$/.exec(path);
if (m) {
this.jumpToElement(m[1]);
- return;
+ return this.replaceState(path);
}
const oldPath = this.router.currentURL;
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/url-test.js b/app/assets/javascripts/discourse/tests/unit/lib/url-test.js
index bdb99b3ce48..1d1cc04dc89 100644
--- a/app/assets/javascripts/discourse/tests/unit/lib/url-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/lib/url-test.js
@@ -154,10 +154,15 @@ module("Unit | Utility | url", function () {
test("anchor handling", async function (assert) {
sinon.stub(DiscourseURL, "jumpToElement");
+ sinon.stub(DiscourseURL, "replaceState");
DiscourseURL.routeTo("#heading1");
assert.ok(
DiscourseURL.jumpToElement.calledWith("heading1"),
"in-page anchors call jumpToElement"
);
+ assert.ok(
+ DiscourseURL.replaceState.calledWith("#heading1"),
+ "in-page anchors call replaceState with the url fragment"
+ );
});
});