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
In our current setup, we are using a singleton with all the available routes, in the form of objects generated through the linkOptions() function. This is a useful pattern because it protects us in case where some route changes, so that we only need to change it in one place.
We use that singleton, like so:
//urls.tsimport{linkOptions}from'@tanstack/react-router';exportconsturls={home: ()=>{returnlinkOptions({to: '/'})},articles: ()=>{returnlinkOptions({to: `${urls.home().to}articles`})}}//exampleimport{urls}from'~/singletons/urls.ts';<Link{...urls.articles()}> Go to articles</Link>
That's fine.
The issue arises when I want to use the same urls singleton with something that makes use of from, like for example useSearch()
if I do useSearch({ from: urls.articles().to }) I am getting a type mismatch error, saying that /articles does not match the expected value /articles/
This causes some friction because a mechanism that was otherwise very reusable now becomes not-so-reusable, and to me it's not very obvious why the from prop expects a trailing /.
So, can someone explain why is that so, and, at the end of the day, if there needs to be a discrepancy between from and to expected values?
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In our current setup, we are using a singleton with all the available routes, in the form of objects generated through the
linkOptions()
function. This is a useful pattern because it protects us in case where some route changes, so that we only need to change it in one place.We use that singleton, like so:
That's fine.
The issue arises when I want to use the same urls singleton with something that makes use of
from
, like for exampleuseSearch()
if I do
useSearch({ from: urls.articles().to })
I am getting a type mismatch error, saying that/articles
does not match the expected value/articles/
This causes some friction because a mechanism that was otherwise very reusable now becomes not-so-reusable, and to me it's not very obvious why the
from
prop expects a trailing/
.So, can someone explain why is that so, and, at the end of the day, if there needs to be a discrepancy between
from
andto
expected values?Thanks.
Beta Was this translation helpful? Give feedback.
All reactions