Optional path segment options #6851
znycheporuk
started this conversation in
Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Version
1.18.1
Issue
Right now there is a problem with ambiguous routes, if optional path segment is used before dynamic path segment, for example:
app/ ├── routes/ │ ├── ($lang)._index.tsx │ ├── ($lang).$slug.tsx └── root.tsx
Expected behaviour
/
($lang)._index.tsx
/fr
($lang)._index.tsx
/some-slug
($lang).$slug.tsx
<—/en/some-slug
($lang).$slug.tsx
Current behaviour
/
($lang)._index.tsx
/fr
($lang)._index.tsx
/some-slug
($lang)._index.tsx
<—/en/some-slug
($lang).$slug.tsx
Proposal
Add new field to
handle
export, to configure possible values of optional path segment:Then, if
lang
param equals to one of configured values —($lang)._index
should be used, in another case — use($lang).$slug
.It can be set on root route, and overridden in any other route, same as
meta
.If not provided — fallback to current behaviour.
Discussion
Similar issue described here #5883
Here is a short summary by @kiliman
One of the most popular usages of optional path segment is using it for
lang
param, as shown higher.In this case we know languages we support e.g.
["en", "es", "fr"]
, and therefore, we can check if:lang?
matches one of them and make a decision if we should use($lang)._index
or($lang).$slug
.Beta Was this translation helpful? Give feedback.
All reactions