-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
[Bug v6]: navigate() and <Navigate> doesn't produce the same result #7962
Comments
Because you are rendering the If you include the Now, that being said, we do intend to support this feature. @mjackson describes this in #7960 Regarding the issue with |
Thanks @chaance for your reply. I am confuse now. I have seen here #7285 that the recommended way to do optional parameters is by nesting routes with the same element so that The use case here is fairly simple:
This is at (3.) where Also, is there a way to console.log() the matched route inside a component so I can debug it better? |
Here you go: https://codesandbox.io/s/react-router-useparams-lcn4d?file=/src/App.js I have refactored the CSB to get closer to what I want to achieve Change in Route matching<Route path="home">
<Route path="/" element={<Home />} />
<Route path=":actionOrId" element={<Home />} />
<Route path=":actionOrId/:action" element={<Home />} />
</Route> I have removed Optional parametersAs v6 stopped supporting optional parameter, I am doing validation inside the Home component with a parameter that can take different value format. The possible cases are:
Line 45 to 48 of the CSB is the validation navigate(...) vs. <Navigate ... />If you comment/uncomment lines 46 and 47 you should normally have different behavior. |
You need to run |
Thanks @timdorr. Why does |
It can work inside of an event handler just fine, but not directly inside of the render function of the component. That creates a side effect on every render, which you should always put inside of |
Got it. Thanks @timdorr |
What version of React Router are you using?
17.0.1
Steps to Reproduce
CSB: https://codesandbox.io/s/react-router-useparams-lcn4d?file=/src/App.js
This CSB reproduces what I have in local but - I don't know why -
useParams()
doesn't capture the parameter.The whole code to reproduce the bug is short though
You need to comment/uncomment the following lines
Expected Behavior / Actual behavior
Path:
/main/12345
Action: Both
navigate('..', { replace: true })
andnavigate('/main', { replace: true })
Expected behavior: redirect to
/main
Actual behavior: stays at
/main/12345
If you replace
navigate(...)
by:return <Navigate to={'..'} replace={true} />
orreturn <Navigate to={'/models'} replace={true} />
it redirects to
/main
as expected.The text was updated successfully, but these errors were encountered: