You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TanStack router have great support for i18n out of the box. After setting it up I came upp with a few questions or suggestions for improvements that would really make the i18n experience excellent.
Solution 1:
This is how I do it today. For every link I need to explicit read the lang param and set it again. It's a little bit cumbersome but it works.
constExample1=()=>{const{ lang ="en"}=useParams({strict: false});return(<Linkto="/$lang/upgrade"params={{lang}}>Upgrade</Link>);};
Solution2:
By using the generic LinkOptions I get type-safety on all paths but without the strict types on params.
This works great. The router will just pickup whatever params I'm currently having which is exactly what I want for i18n.
The issue is I loose type-safety on all other params as well.
Solution:
A type helper that can Omit a specific param key from a LinkComponent. I this way it would be easy to build utility components that handle some parameters for you.
constI18nLink: OmitParams<LinkComponent<"a">,"lang">=(props)=>{const{ lang ="en"}=useParams({strict: false});return<Link{...props}params={{ ...props.params, lang }}/>;};
...
<I18nLinkto="/$lang/upgrade">Upgrade</I18nLink>
Looking at the code I seem that I need to Override PathParamOptions in some way.
Let me know if there's a better way to do this. I think it would be very beneficial for an easy way to override the types for params and search that you want to manage with your custom logic.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
TanStack router have great support for i18n out of the box. After setting it up I came upp with a few questions or suggestions for improvements that would really make the i18n experience excellent.
Solution 1:
This is how I do it today. For every link I need to explicit read the lang param and set it again. It's a little bit cumbersome but it works.
Solution2:
By using the generic
LinkOptions
I get type-safety on all paths but without the strict types on params.This works great. The router will just pickup whatever params I'm currently having which is exactly what I want for i18n.
The issue is I loose type-safety on all other params as well.
Solution:
A type helper that can Omit a specific param key from a LinkComponent. I this way it would be easy to build utility components that handle some parameters for you.
Looking at the code I seem that I need to Override
PathParamOptions
in some way.Let me know if there's a better way to do this. I think it would be very beneficial for an easy way to override the types for params and search that you want to manage with your custom logic.
Beta Was this translation helpful? Give feedback.
All reactions