fix!: Return x-default
alternate link also for sub pages when using localePrefix: 'always'
and update middleware matcher suggestion in docs
#1720
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.
Previously, we suggested a middleware matcher that looked like this:
Even though the hardcoded locales need to be updated when new locales are added, this was suggested in light of providing an error-free getting started experience.
However, based on the apps I've seen over time, it seems like this choice was unpopular and users typically go for a matcher that looks like this:
While this avoids hardcoding locales, it requires extra care to match pathnames that contain a dot (e.g.
/users/jane.doe
).To align better with user expectations, we now suggest the negative lookahead in the getting started docs and point out the case with pathnames containing dots. As an extra benefit, it makes it significantly easier to switch between routing strategies and add custom prefixes.
With the new matcher in place, the middleware now also returns an
x-default
alternate link for non-root pathnames (previously only one for/
was returned when usinglocalePrefix: 'always'
). Due to this, please update your middleware matcher as shown in the getting started docs if you're using alternate links.Related discussions: