How to redirect to another route programmatically
See original GitHub issueI have an <input />
with a handler on ‘enter’ key up event handler.
How can I redirect to /app?keyword=[input_value]
in that event handler.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:2
- Comments:27 (6 by maintainers)
Top Results From Across the Web
Programmatically navigate using React router - Stack Overflow
Rendering a <Redirect> will navigate to a new location. The new location will override the current location in the history stack, like server- ......
Read more >Programmatically Navigate with React Router - Telerik
The primary way you programmatically navigate using React Router v4+ is by using a <Redirect /> component, and it's a recommended method that ......
Read more >Programmatic Navigation in React using react-router
We can redirect using <Redirect> component by simply passing the route we want to redirect to and rendering the component. It already comes ......
Read more >Programmatically navigate with React Router (and Hooks)
How to programmatically navigate with React Router v6 and the new useNavigate hook. ... Redirect Default or 404 Routes with React Router.
Read more >Redirecting the Router to Another Route - Rangle.io
The pathMatch property, which is required for redirects, tells the router how it should match the URL provided in order to redirect to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is crazy, the documentation is terrible when describing something as basic as navigating programmatically. The link you post still doesn’t make sense to me, my component gets a ‘history’ not a ‘router’ passed into its props (v2), so I still have no idea from the docs how to do basic navigation in my code.
If the documentation was better people wouldn’t need to comment on old Github issues. So frustrating.
Say what you want but the docs are bad and confusing. To stop the user from ever even visiting a page thus not causing any unwanted API-calls happening the best method I found is to put a middleware function to route’s onEnter -property and check if user is logged in / has required privileges. Not so easy to just “read the docs” and know what to do. So I have route like this:
And then middleware function like this:
Which works but was way too hard to figure out and I think the hackiness still shows and it still feels to me a bit ambiguous