It’s similar to how it’s done in v4, two arguments, the second being an object with a state
property.
navigate(
'thepath',
{
state: {
//...values
}
}
})
From the migration guide: Use navigate instead of history
If you need to replace the current location instead of push a new one
onto the history stack, usenavigate(to, { replace: true })
. If you
need state, usenavigate(to, { state })
. You can think of the first
arg to navigate as your and the other arg as thereplace
andstate
props.
To access the route state in the consuming component use the useLocation
React hook:
const { state } = useLocation();