Skip to content

fix(compactRoutes): strip stale locale param in by-path resolver#4015

Open
Togetic wants to merge 1 commit into
nuxt-modules:mainfrom
Togetic:fix/compact-routes-bypath-locale-param
Open

fix(compactRoutes): strip stale locale param in by-path resolver#4015
Togetic wants to merge 1 commit into
nuxt-modules:mainfrom
Togetic:fix/compact-routes-bypath-locale-param

Conversation

@Togetic

@Togetic Togetic commented Jun 28, 2026

Copy link
Copy Markdown

🔗 Linked issue

Fixes #4002

📚 Description

With experimental.compactRoutes, the route table is asymmetric: the default-locale route has no :locale param, while the compact route for the other locales does. There are two resolvers in runtime/utils.ts:

  • the by-name resolver correctly does delete route.params.locale when retargeting to the default-locale route;
  • the by-path resolver swaps route.name to the default-locale route but does not delete params.locale.

So resolving a prefixed path to the default locale from a non-default-locale URL — e.g. localeRoute(route.path, defaultLocale), common in SEO head composables that build x-default / hreflang links — hands vue-router a named location carrying a locale param the target route doesn't declare:

[Vue Router warn]: Discarded invalid param(s) "locale" when navigating.

…once per SSR request for every non-default-locale URL (default-locale URLs are silent). It's dev-only and functionally harmless — vue-router's pickParams drops the stray param, so canonical / hreflang / hrefs stay correct — but it's per-request console noise.

This is a follow-up to #3975, which fixed several compact-route router warnings but missed this code path.

Fix: mirror the existing delete route.params.locale from the by-name branch into the by-path branch, under the same __I18N_COMPACT_ROUTES__ guard.

✅ Verification

  • pnpm test:types, pnpm lint, and pnpm test:unit all pass.
  • Verified locally: the warning drops to 0 across non-default-locale routes, and generated canonical / hreflang are unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed localized routes so they no longer carry an outdated locale parameter when compact routing is enabled.

With `experimental.compactRoutes`, the by-name resolver deletes the
inherited `locale` param when retargeting a prefixed path to the default
locale, but the by-path resolver did not. So resolving a prefixed path
to the default locale from a non-default-locale URL — e.g.
`localeRoute(route.path, defaultLocale)`, common in SEO head composables
that build x-default / hreflang links — handed vue-router a named
location carrying a `locale` param the target route doesn't declare,
logging `[Vue Router warn]: Discarded invalid param(s) "locale" when
navigating.` once per SSR request (dev only; functionally harmless).

Mirror the existing `delete route.params.locale` from the by-name branch
into the by-path branch, under the same `__I18N_COMPACT_ROUTES__` guard.
Follow-up to nuxt-modules#3975, which fixed several compact-route router warnings but
missed this code path.

Fixes nuxt-modules#4002
@Togetic Togetic requested a review from BobbieGoede as a code owner June 28, 2026 09:47
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 79db34cc-5160-4626-8cda-e1ec199888d4

📥 Commits

Reviewing files that changed from the base of the PR and between bd54cb9 and b0cf535.

📒 Files selected for processing (1)
  • src/runtime/utils.ts

Walkthrough

In resolveLocalizedRouteByPath within src/runtime/utils.ts, a new conditional block removes the locale key from route.params (cast to RouteLikeWithName) when the resolved route name corresponds to an existing per-locale route and the __I18N_COMPACT_ROUTES__ flag is enabled. This prevents per-locale routes from inheriting a locale param that originates from compact-route resolution.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: removing a stale locale param in the by-path resolver for compact routes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant