Typescript Error with LinkComponent.. Best Practice?
Currently i am struggeling with the Link Component Type safety.
I have 3 routes that are using the same component for searching users on my plattform.
So since i also use search params with my search, i use the navigate function with replace to set up the search params.
const navigate = useNavigate({ from: routerLocation.to });
to let the router know where the user is, i have to use the from property in the useNavigate Hook. But regarding it can be 3 different routes i am a bit confused. I tried using a Route that i get via props. See example above.
But now the navigate function has a ts problem:
thats the function.
The error says:
So in short the navigate function doesnt know where it is. I cannot find anything regarding this in the docs.
How would this be handled properly?2 Replies
useful-bronze•7mo ago
Hello, if routes have the same search parameters you can probably add a
to: '.'
parameter to the navigate, to prevent TS from complaining.correct-apricotOP•7mo ago
@Tiago Thank you very much!