[DRAFT] feat: experimental route resolution enhancement #3358
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This functionality is based on the proposed method of resolving routes as seen in the I18n Routing RFC, see the Resolving routes (methods) section.
Todo
router.resolve
typeDescription
This adds an experimental feature which changes the behavior of Vue Router's
router.resolve
to resolve localized routes, this can be configured withexperimental.routeResolutionEnhancement
.Configuration
false
(default)Disables the feature.
'explicit'
(recommended for now)Route resolution is localized when explicitly opting into the behavior by passing an object with
{ locale: true | Locale }
as third argument.'implicit'
Route resolution is localized by default, can be explicitly disabled by passing
{ locale: false }
as third argument.Compatibility
The
'implicit'
enhancement is most powerful as it changes all route resolution in a project to be localized, this could be an issue for modules/plugins and cross project code/tests.Explicitly opting out of the localized resolution would be necessary to preserve the same (predictable) behavior regardless of the configured enhancement option, this is used internally in this module for localized resolution as well.
Considerations
Ironically, the
'implicit'
option could be problematic for projects that already use this module since we have no control overNuxtLink
. If localized links are set up usinglocalePath
(e.g.<NuxtLink :to="localePath(..., locale)"/>
), the implicit localization will default to the current locale within theNuxtLink
component, losing the explicitly passedlocale
.In that case users can either use
localeRoute
instead oflocalePath
as it passes an object (with correct localized name prop) or use theNuxtLinkLocale
component.There may be other scenarios where the implicit route localization could cause unexpected behavior, the easiest way to find out is by testing the experimental options in real projects.