A platform for community discussion. Free, open, simple.
FIX: Custom sidebar section link with `/` path leading to blank page (#23661)
Alan Guo Xiang Tanfa243484ca8d
diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/section-link.jsindex 33ab14900bb..c017025cc98 100644--- a/app/assets/javascripts/discourse/app/lib/sidebar/section-link.js+++ b/app/assets/javascripts/discourse/app/lib/sidebar/section-link.js@@ -2,6 +2,7 @@ import { tracked } from "@glimmer/tracking";import { bind } from "discourse-common/utils/decorators";import RouteInfoHelper from "discourse/lib/sidebar/route-info-helper";import discourseLater from "discourse-common/lib/later";+import { defaultHomepage } from "discourse/lib/utilities";const TOUCH_SCREEN_DELAY = 300;const MOUSE_DELAY = 250;@@ -26,7 +27,13 @@ export default class SectionLink {if (!this.externalOrFullReload) {const routeInfoHelper = new RouteInfoHelper(router, value);- this.route = routeInfoHelper.route;++ if (routeInfoHelper.route === "discovery.index") {+ this.route = `discovery.${defaultHomepage()}`;+ } else {+ this.route = routeInfoHelper.route;+ }+this.models = routeInfoHelper.models;this.query = routeInfoHelper.query;}diff --git a/spec/system/custom_sidebar_sections_spec.rb b/spec/system/custom_sidebar_sections_spec.rbindex bf09c1a3cf6..9427657cf69 100644--- a/spec/system/custom_sidebar_sections_spec.rb+++ b/spec/system/custom_sidebar_sections_spec.rb@@ -55,6 +55,21 @@ describe "Custom sidebar sections", type: :system doexpect(sidebar).to have_section_link("My preferences", target: "_self")end+ it "allows the user to create custom section with `/` path which generates a link based on the first item in the `top_menu` site settings" do+ SiteSetting.top_menu = "read|posted|latest"++ sign_in user+ visit("/latest")++ sidebar.click_add_section_button+ section_modal.fill_name("My section")+ section_modal.fill_link("Home", "/")+ section_modal.save++ expect(sidebar).to have_section("My section")+ expect(sidebar).to have_section_link("Home", href: "/read")+ end+it "allows the user to create custom section with /pub link" dosign_in uservisit("/latest")