FIX: URL fragments not purging (#19324)

Fixes issue introduced in commit 2704a02e3a. Once a user visited an in-page anchor, that URL "stuck" in the browser's address bar. See also https://meta.discourse.org/t/anchors-url-not-purge-when-page-changed/244484 for a detailed report.
This commit is contained in:
Penar Musaraj 2022-12-06 09:52:59 -05:00 committed by GitHub
parent e5a18dddac
commit 57fe57e7ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -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;

View File

@ -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"
);
});
});