In react-router, there is a hook to retrieve path parameters, for example "/users/:id" where the code can access the id value.
In this example :id is a slug for a path parameter, and within your page component you'd get this id like so:
function UserPage() {
const { id } = useParams();
return <>{id}</>;
}
More details here
However, the useParams hook only gives me a getter for the segment and not a setter. So for example if I was in "/users/abc" and want to change it to "/users/def", the only way I can currently do that is by modifying the URL, but that's prone to errors, like missing out on query parameters, etc.
Is there a reliable way within react-router itself through which I can set the segment (My use case requires using a basename, so I don't feel safe haphazardly modifying the URL)? I can't seem to find it within the documentation, and I am unfamiliar with a lot of terms and synonyms that might make it easier to find it.