Skip to content

fix(router): keep "/" as the home path when the backend reports a langcode - #825

Merged
Decipher merged 1 commit into
developfrom
fix/router-home-path-langcode
Sep 17, 2026
Merged

Decipher merged 1 commit into
developfrom
fix/router-home-path-langcode

Conversation

@Decipher

@Decipher Decipher commented Sep 9, 2026

Copy link
Copy Markdown
Member

Closes #824.

DruxtRouter.getRedirect() now accepts / as the home path alongside /<langcode> and /<langcode>/. Any other path that resolves to the home path still redirects to the prefixed home path.

Request isHomePath props.langcode Before After
/ true en /en no redirect
/es true es no redirect no redirect
/node/1 true es /es /es

Why

A backend can legitimately report a langcode for an unprefixed path. Entity routes always have, and the Views langcode patch (#3273228) makes Views routes do the same instead of returning NULL. The router treated that as a wrong URL and bounced / to /en, a client side navigation that throws away the SSR-only data-fetch-key attributes. That is what broke the druxt-devel-template, multilingual and umami-homepage e2e specs in examples/druxt-site on #818.

The redirect target still assumes the URL prefix equals the langcode. That is a separate bug and stays out of this PR.

Verification

  • packages/router/test/router.test.js gains three getRedirect cases. With the fix reverted and the test kept: Expected: false, Received: "/en". With the fix: 15 passed.
  • eslint and cspell clean on both files.
  • Changeset: druxt-router patch.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where the unprefixed home path (/) could incorrectly redirect to a language-prefixed path.
    • Preserved expected redirects for non-home paths and trailing-slash handling.
    • Added coverage for language-aware home-path routing behavior.

@changeset-bot

changeset-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f97dd5e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
druxt-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: f532a594-c69b-437b-86e7-da4ee017e8da

📥 Commits

Reviewing files that changed from the base of the PR and between c31eba5 and f97dd5e.

📒 Files selected for processing (2)
  • packages/router/src/router.js
  • packages/router/test/router.test.js

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The router no longer redirects / to a language-prefixed home path when the route reports a language code. Tests cover root, prefixed home, and non-home paths. A patch changeset records the fix.

Changes

Router home-path handling

Layer / File(s) Summary
Canonical home-path redirect handling
packages/router/src/router.js, packages/router/test/router.test.js, .changeset/quiet-roads-return.md
getRedirect preserves / for language-aware home routes, keeps prefixed home paths unchanged, and redirects non-home paths to the prefixed home path. Tests cover these cases, and the changeset declares a patch release.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to f97dd

The root home-path redirect fix is covered by focused tests, with no supported merge-blocking risk remaining.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main router fix: preserving "/" as the home path when the backend reports a language code.
Linked Issues check ✅ Passed The change satisfies issue #824. DruxtRouter.getRedirect() accepts /, /<langcode>, and /<langcode>/ for a home route with props.langcode. Other paths that resolve to the home route return th…
Out of Scope Changes check ✅ Passed The changes are limited to the issue #824 behavior, its automated tests, and the related druxt-router patch changeset. No change addresses the separate URL-prefix and language-code mismatch issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/router-home-path-langcode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.79%. Comparing base (d26a6c7) to head (f97dd5e).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #825   +/-   ##
========================================
  Coverage    81.79%   81.79%           
========================================
  Files          112      112           
  Lines         3054     3054           
  Branches       654      654           
========================================
  Hits          2498     2498           
  Misses         452      452           
  Partials       104      104           
Files with missing lines Coverage Δ
packages/router/src/router.js 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Decipher
Decipher force-pushed the fix/router-home-path-langcode branch from c31eba5 to f97dd5e Compare September 17, 2026 08:18
@Decipher
Decipher merged commit 27e7c50 into develop Sep 17, 2026
15 checks passed
@Decipher
Decipher deleted the fix/router-home-path-langcode branch September 17, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Router redirects "/" to "/<langcode>" when the backend reports a langcode for the home path

1 participant