fix(compactRoutes): strip stale locale param in by-path resolver#4015
fix(compactRoutes): strip stale locale param in by-path resolver#4015Togetic wants to merge 1 commit into
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughIn Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🔗 Linked issue
Fixes #4002
📚 Description
With
experimental.compactRoutes, the route table is asymmetric: the default-locale route has no:localeparam, while the compact route for the other locales does. There are two resolvers inruntime/utils.ts:delete route.params.localewhen retargeting to the default-locale route;route.nameto the default-locale route but does not deleteparams.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 buildx-default/hreflanglinks — hands vue-router a named location carrying alocaleparam the target route doesn't declare:…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
pickParamsdrops 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.localefrom the by-name branch into the by-path branch, under the same__I18N_COMPACT_ROUTES__guard.✅ Verification
pnpm test:types,pnpm lint, andpnpm test:unitall pass.Summary by CodeRabbit