-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v6] [Feature]: Use Navigate outside from render component #7970
Comments
You're looking for useNavigate: https://github.com/remix-run/react-router/blob/dev/docs/api-reference.md#usenavigate |
For example, i'm using xstate machine and the routes are controlled by states, using v6, i can't change route path from "outside" |
@timdorr as another example of navigating from outside a component, image you want to have a single place where 401 response status codes from the backend send the user back to the home page. You could have a hook that gives you a client ( The method I've with v5 is, rather than e.g.: ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById("root")
); create my own, which exposes the const history = createBrowserHistory();
ReactDOM.render(
<Router history={history}>
<App />
</Router>,
document.getElementById("root")
); (This has to be updated slightly for v6 anyway, see https://stackoverflow.com/q/69859509/3001761.) |
What is the new or updated feature that you are suggesting?
According to the docs: https://github.com/remix-run/react-router/blob/dev/docs/api-reference.md#Navigate
At this moment it's possible to use Navigate only in render component.
Why should this feature be included?
Implement
history.push
like function, to change route location from outside.The text was updated successfully, but these errors were encountered: