FIX: Back button shenanigans when redirecting from index routes

This is a problem that has long plagued Discourse. The root issue here
is that we have to implement our own link click handler, because
Discourse allows users to create HTML blobs of content with links, and
when those links are clicked they must be handled by the Ember router.

This always involved a certain amount of use of private Ember APIs which
of course evolved over time.

The API has more or less stabilized in the last two years, however we
have hacks in our URLs to handle a dynamic root path, depending on how
forums have set up their filters and in what order.

This patch adds a special case for the root path so we needn't update
the URL ourselves otherwise, which preserves the back button on index
routes. The update call would otherwise insert an extra history event if
a route redirected on transition, breaking the back button.
This commit is contained in:
Robin Ward 2019-06-21 14:37:34 -04:00
parent e51de4cc25
commit 02f6db4e59
3 changed files with 12 additions and 5 deletions

View File

@ -433,8 +433,6 @@ const DiscourseURL = Ember.Object.extend({
if (discoveryTopics) {
discoveryTopics.resetParams();
}
router._routerMicrolib.updateURL(path);
}
const split = path.split("#");
@ -445,7 +443,16 @@ const DiscourseURL = Ember.Object.extend({
elementId = split[1];
}
const transition = router.handleURL(path);
// The default path has a hack to allow `/` to default to defaultHomepage
// via BareRouter.handleUrl
let transition;
if (path === "/") {
router._routerMicrolib.updateURL(path);
transition = router.handleURL(path);
} else {
transition = router.transitionTo(path);
}
transition._discourse_intercepted = true;
const promise = transition.promise || transition;
promise.then(() => jumpToElement(elementId));

View File

@ -59,7 +59,7 @@ export default createWidget("hamburger-menu", {
if (currentUser.admin) {
links.push({
href: "/admin/site_settings/category/required",
href: "/admin/site_settings",
icon: "cog",
label: "admin.site_settings.title",
className: "settings-link"

View File

@ -90,7 +90,7 @@ createWidget("user-menu-links", {
label: "user.preferences",
className: "user-preferences-link",
icon: "cog",
href: `${path}/preferences/account`
href: `${path}/preferences`
});
return h("ul.menu-links-row", [