Previous pathname #9860
Replies: 4 comments 2 replies
-
I need similar feature too, because workaround with setting prop I need to resolve redirecting from Page A to Page B and clicking on the browser Back button => there is no way how to set My current workaround is similar to @lasse-instructr, but causing unnecessary rerender. |
Beta Was this translation helpful? Give feedback.
-
I'm going to convert this to a discussion so it can go through our new Open Development process. Please upvote the new Proposal if you'd like to see this considered! |
Beta Was this translation helpful? Give feedback.
-
Upvoted the proposal but also wanted to add my scenario to the mix. I have state that needs to be initialized or modified conditionally based on what route the user was redirected from. Being redirected from some paths means I initialize or modify state with specific values and while my workaround has worked fine but it's much much more cumbersome than just checking a Hope to see something like this added in the future! |
Beta Was this translation helpful? Give feedback.
-
一直在关注该讨论,现在已经 2024 了,官方还是没有给出积极的回复,这个功能应用的场景很多,希望官方能尽快给出解决方案,我希望能在原有的基础上新增 api const { from } = useLoaction() |
Beta Was this translation helpful? Give feedback.
-
What is the new or updated feature that you are suggesting?
We can get the current pathname through the
useLocation()
hook.I want to get the pathname for the last page visited for the usage of a back button.
navigate(-1)
does not suffice, as I need to know the previous route to decide whether or not it makes sense to navigate back to.I have implemented a simple context for this purpose, but it would be nice if it was provided through React Router:
I hope that you get the gist of it.
Note: If the previous route was outside the app we will not have access to the pathname. In this case, I think that the state variable should return
undefined
.Why should this feature be included?
I believe it is a common use case that you want to know the previous route.
Beta Was this translation helpful? Give feedback.
All reactions