mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 03:12:46 +08:00
FIX: Don't unnecessarily scrub query params from homepage (#25665)
Seems like an accident that the homepage route will always strip all query params from the URL.. This fixes that :)
This commit is contained in:
parent
d1ebca90ff
commit
4f75cee6d2
|
@ -21,12 +21,14 @@ export default function applyRouterHomepageOverrides(router) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const homepageRewriteParam = "_discourse_homepage_rewrite";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a magic URL which `discovery-index` will redirect to.
|
* Returns a magic URL which `discovery-index` will redirect to.
|
||||||
* We watch for this, and then perform the rewrite in the router.
|
* We watch for this, and then perform the rewrite in the router.
|
||||||
*/
|
*/
|
||||||
export function homepageDestination() {
|
export function homepageDestination() {
|
||||||
return `/${defaultHomepage()}?_discourse_homepage_rewrite=1`;
|
return `/${defaultHomepage()}?${homepageRewriteParam}=1`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function rewriteIfNeeded(url, transition) {
|
function rewriteIfNeeded(url, transition) {
|
||||||
|
@ -34,12 +36,16 @@ function rewriteIfNeeded(url, transition) {
|
||||||
if (
|
if (
|
||||||
intentUrl?.startsWith(homepageDestination()) ||
|
intentUrl?.startsWith(homepageDestination()) ||
|
||||||
(transition?.intent.name === `discovery.${defaultHomepage()}` &&
|
(transition?.intent.name === `discovery.${defaultHomepage()}` &&
|
||||||
transition?.intent.queryParams["_discourse_homepage_rewrite"])
|
transition?.intent.queryParams[homepageRewriteParam])
|
||||||
) {
|
) {
|
||||||
const params = url.split("?", 2)[1];
|
const params = (intentUrl || url).split("?", 2)[1];
|
||||||
url = "/";
|
url = "/";
|
||||||
if (params) {
|
if (params) {
|
||||||
url += `?${params}`;
|
const searchParams = new URLSearchParams(params);
|
||||||
|
searchParams.delete(homepageRewriteParam);
|
||||||
|
if (searchParams.size) {
|
||||||
|
url += `?${searchParams.toString()}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
|
|
|
@ -74,4 +74,18 @@ acceptance("Dynamic homepage handling", function () {
|
||||||
await click(".nav-item_categories a");
|
await click(".nav-item_categories a");
|
||||||
assertOnCategories("/categories");
|
assertOnCategories("/categories");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("it passes query params through", async function (assert) {
|
||||||
|
await visit("/?test-one=true");
|
||||||
|
|
||||||
|
const router = getOwner(this).lookup("service:router");
|
||||||
|
assert.strictEqual(router.currentURL, "/?test-one=true");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("it removes the _discourse_homepage_rewrite param from the URL", async function (assert) {
|
||||||
|
await visit("/?_discourse_homepage_rewrite=1&test-one=true");
|
||||||
|
|
||||||
|
const router = getOwner(this).lookup("service:router");
|
||||||
|
assert.strictEqual(router.currentURL, "/?test-one=true");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user