Skip to content

Commit

Permalink
FIX: Navigating to home via route name (#24460)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq committed Nov 20, 2023
1 parent 5276afa commit c5affa9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Expand Up @@ -30,7 +30,11 @@ export function homepageDestination() {

function rewriteIfNeeded(url, transition) {
const intentUrl = transition?.intent?.url;
if (intentUrl?.startsWith(homepageDestination())) {
if (
intentUrl?.startsWith(homepageDestination()) ||
(transition?.intent.name === `discovery.${defaultHomepage()}` &&
transition?.intent.queryParams["_discourse_homepage_rewrite"])
) {
const params = url.split("?", 2)[1];
url = "/";
if (params) {
Expand Down
Expand Up @@ -9,7 +9,7 @@ export default class DiscoveryIndex extends DiscourseRoute {

beforeModel(transition) {
const url = transition.intent.url;
const params = url.split("?", 2)[1];
const params = url?.split("?", 2)[1];
let destination = homepageDestination();
if (params) {
destination += `&${params}`;
Expand Down
Expand Up @@ -29,6 +29,9 @@ acceptance("Dynamic homepage handling", function () {
await router.transitionTo("/").followRedirects();
assertOnLatest("/");

await router.transitionTo("discovery.index").followRedirects();
assertOnLatest("/");

await click(".nav-item_latest a");
assertOnLatest("/latest");

Expand Down Expand Up @@ -65,6 +68,9 @@ acceptance("Dynamic homepage handling", function () {
await router.transitionTo("/").followRedirects();
assertOnCategories("/");

await router.transitionTo("discovery.index").followRedirects();
assertOnCategories("/");

await click(".nav-item_categories a");
assertOnCategories("/categories");
});
Expand Down

1 comment on commit c5affa9

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/clicking-home-from-admin-panel-results-in-error/286000/8

Please sign in to comment.