mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 23:54:16 +08: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:
parent
7a8442435c
commit
ab5df7b2bd
|
@ -480,6 +480,8 @@ const DiscourseURL = EmberObject.extend({
|
|||
}
|
||||
|
||||
transition._discourse_intercepted = true;
|
||||
transition._discourse_anchor = elementId;
|
||||
|
||||
const promise = transition.promise || transition;
|
||||
promise.then(() => jumpToElement(elementId));
|
||||
}
|
||||
|
|
|
@ -11,7 +11,18 @@ export default DiscourseRoute.extend({
|
|||
if (results.found) {
|
||||
// Avoid polluting the history stack for external links
|
||||
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 "";
|
||||
} else {
|
||||
// 404 body HTML
|
||||
|
|
Loading…
Reference in New Issue
Block a user