I do programmatic navigation using some state data like this
history.push({
pathname: '/some/path',
search: '?the=query',
state: { data: someData }
})
I thought react-router will make state.data
to be undefined
when a situation like a page refresh or a manual URL typing, but it doesn't remove the state.data
in both scenarios
Actually what I want to do is, redirect to an another component if there is no data for the state.data
property
if (!props.location.state.data) {
history.push('/')
}
How can I do that, this is bit confused though, can anyone explain this?
I've found an answer from here
https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState
window.history.replaceState(null, '')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.