mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Preserve anchors in permalink transitions (#10421)
When visiting a permalink with an anchor (e.g. /important-link#notes) the anchor part was being dropped during redirection. The change doesn't have a test. Functions like scrollToPost or scrollToElement don't have any effect in the test environment.
This commit is contained in:
@@ -480,6 +480,8 @@ const DiscourseURL = EmberObject.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
transition._discourse_intercepted = true;
|
transition._discourse_intercepted = true;
|
||||||
|
transition._discourse_anchor = elementId;
|
||||||
|
|
||||||
const promise = transition.promise || transition;
|
const promise = transition.promise || transition;
|
||||||
promise.then(() => jumpToElement(elementId));
|
promise.then(() => jumpToElement(elementId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,18 @@ export default DiscourseRoute.extend({
|
|||||||
if (results.found) {
|
if (results.found) {
|
||||||
// Avoid polluting the history stack for external links
|
// Avoid polluting the history stack for external links
|
||||||
transition.abort();
|
transition.abort();
|
||||||
DiscourseURL.routeTo(results.target_url);
|
|
||||||
|
let url = results.target_url;
|
||||||
|
|
||||||
|
if (transition._discourse_anchor) {
|
||||||
|
// Remove the anchor from the permalink if present
|
||||||
|
url = url.split("#")[0];
|
||||||
|
|
||||||
|
// Add the anchor from the transition
|
||||||
|
url += `#${transition._discourse_anchor}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscourseURL.routeTo(url);
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
// 404 body HTML
|
// 404 body HTML
|
||||||
|
|||||||
Reference in New Issue
Block a user