Skip to content

fix(NuxtLinkLocale): allow string paths in to prop (fixes #4005)#4006

Closed
houtanrocky wants to merge 2 commits into
nuxt-modules:mainfrom
houtanrocky:houtan-rocky/fix/nuxtlinklocale-to-prop-type
Closed

fix(NuxtLinkLocale): allow string paths in to prop (fixes #4005)#4006
houtanrocky wants to merge 2 commits into
nuxt-modules:mainfrom
houtanrocky:houtan-rocky/fix/nuxtlinklocale-to-prop-type

Conversation

@houtanrocky

@houtanrocky houtanrocky commented Jun 15, 2026

Copy link
Copy Markdown

🔗 Linked issue

resolves #4005

📚 Description

Problem

The NuxtLinkLocale component currently rejects plain string paths passed to the to prop, even though the documentation shows examples like to="/".

<NuxtLinkLocale to="/">Home</NuxtLinkLocale>  <!-- ❌ TypeScript error -->

TypeScript reports:

Type 'string' is not assignable to type 'RouteLocationNamedI18n<keyof RouteNamedMapI18n> | undefined'

This is because the to prop is incorrectly typed as RouteLocationNamedI18n, a generated type that only accepts named route objects.

Solution

Change the to prop type to RouteLocationRaw (the union string | RouteLocation), which matches:

  • The documented usage
  • The actual runtime behavior (already works)
  • The <NuxtLink> component's to prop type

Changes

type NuxtLinkLocaleProps<CustomProp extends boolean = false> = Omit<NuxtLinkProps<CustomProp>, 'to'> & {
-  to?: import('vue-router').RouteLocationNamedI18n
+  to?: import('vue-router').RouteLocationRaw
  locale?: Locale
}

Impact

  • Type‑only change – no runtime impact
  • Non‑breakingRouteLocationRaw is a supertype; all existing named‑route usage remains valid
  • Matches documentation and user expectations

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility for locale-aware links by broadening the accepted destination format for locale-localized NuxtLinkLocale routing.
  • Tests
    • Added coverage to ensure string-path destinations correctly render localized href values under the prefix routing strategy when typed pages are enabled.
  • Chores
    • Updated the basic routing fixture to include an additional locale-aware link for verification.

@houtanrocky houtanrocky requested a review from BobbieGoede as a code owner June 15, 2026 17:06
@coderabbitai

coderabbitai Bot commented Jun 15, 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: a3147133-c1ab-4701-8aa0-7c3c77dac55b

📥 Commits

Reviewing files that changed from the base of the PR and between 80c5102 and 33832bc.

📒 Files selected for processing (2)
  • specs/fixtures/basic/pages/index.vue
  • specs/routing_strategies/prefix.spec.ts

Walkthrough

The to prop type in NuxtLinkLocaleProps within src/runtime/components/NuxtLinkLocale.ts is changed from import('vue-router').RouteLocationNamedI18n to import('vue-router').RouteLocationRaw, broadening accepted route destinations to include string paths alongside named routes and location objects. A fixture template in specs/fixtures/basic/pages/index.vue is updated with a new NuxtLinkLocale element targeting the / path. A test case is added to specs/routing_strategies/prefix.spec.ts validating that the component renders localized href attributes correctly when string paths are provided under the prefix routing strategy with typedPages: true. No other logic or rendering behavior is modified.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 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 accurately describes the main change: allowing string paths in the to prop of NuxtLinkLocale component, which is the primary objective of this type-only fix.
Linked Issues check ✅ Passed The pull request directly addresses issue #4005 by changing the to prop type from RouteLocationNamedI18n to RouteLocationRaw, enabling string paths as documented.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the type definition issue. The fixture addition and test case are minimal and necessary to validate the fix works as intended.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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 and usage tips.

@BobbieGoede

Copy link
Copy Markdown
Member

Thank you for your PR! Rejecting path strings when typedPages is enabled is intentional, paths depend on the configured strategy and custom paths so they're less stable than named routes, and widening to to RouteLocationRaw would remove the localized route name checks and autocompletion entirely.

The docs showing path usage predate typed routes, this should be resolved by #4020 which updates the examples to use named routes and documents the rationale.

@BobbieGoede BobbieGoede closed this Jul 8, 2026
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.

NuxtLinkLocale to prop rejects plain string paths, contradicting documentation

2 participants