Why navigation.state
does not change to idle
after redirect?
#12129
Unanswered
matheus4lves
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on an app that displays a form for allowing users create posts. After the post is created, the action redirects the user to the newly created post.
These are my routes:
This is Create's action:
And this is ViewPost's loader:
Since the Create component has no loader, I was expecting the following navigation state transition:
idle -> submitting -> loading -> idle (Create is rendered -> User submits new post -> ViewPost's loader is called -> ViewPost is rendered)
But I get
idle -> submitting -> loading
When using
redirect
.Besides, the URL changes from
/create
to/post/<id>
, but React Router does not render the ViewPost component. In other words, it redirects but does not trigger a rendering for the ViewPost component.Using the
useNavigate()
hook as a work-around produces the expected result (React Router changes the URL and renders the ViewPost component). However, the navigation state transition is as follows:idle -> submitting -> idle
So, although the loader runs and the component is rendered, the "loading" state is not logged.
I'm logging
navigation.state
in the Root component, where I have this code:As you can see, I'm displaying a Loading component and, because the navigation state transition stops on "loading" (again, when using
redirect
), React Router keeps displaying the Loading component until I either refresh the page or go back and forth.Beta Was this translation helpful? Give feedback.
All reactions