-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Doc] Explain how to change page with useNavigation
#9840
Conversation
@@ -1,5 +1,6 @@ | |||
import { useCallback } from 'react'; | |||
import { useNavigate, To } from 'react-router-dom'; | |||
import { Location } from 'history'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you import the To
type imported from 'react-router-dom' above? It would avoid the added dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because there is any state
key in a To
object. And in our first discussion on it your speak about this state
<ul> | ||
<li> | ||
<button onClick={() => redirect('/dashboard')}> | ||
Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use types as labels for your buttons: Relative url, View name, View name with details, Location, Function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea, applied 👍
Now, I'm thinking: since we offer exactly the same API as usenavigate, why would isers choose to use useredirect ? we should better document usenavigate rather than modify our API to mimic it |
docs/useRedirect.md
Outdated
@@ -46,3 +46,28 @@ redirect(false); | |||
``` | |||
|
|||
Note that `useRedirect` allows redirection to an absolute URL outside the current React app. | |||
|
|||
## `useNavigate` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
polish: I'd put this section in a tip but it's a personal opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Co-authored-by: adrien guernier <adrien@marmelab.com>
…ct-admin into feat/useRedirect/to
To
from react-router
in useRedirect
useNavigation
Problem
Sometimes, you’d like to pass a state when redirecting. However the
redirect
only accept a string.Solution
Change theredirect
andRedirectToFunction
functions signature to accept aLocation
fromreact-router
Document useNavigate
Todo
- [x] Accept the right props- [x] Add a storyituseNavigate more