Linked Questions
167 questions linked to/from How can I programmatically navigate using React Router?
6
votes
1
answer
10k
views
Uncaught TypeError: (0 , react_router_dom__WEBPACK_IMPORTED_MODULE_2__.useHistory) is not a function (React.js) [duplicate]
I use React Router Version 6 then I ran this code below:
import { useHistory } from 'react-router-dom'
function Test() {
const history = useHistory();
history.push('/');
history.replace('/');
...
16
votes
1
answer
6k
views
React-router - check for empty state and redirect? [duplicate]
How can I check for empty state and redirect to the first route, if needed?
I have my routes.js
export default (
<Route path="/" component={App}>
<IndexRoute component={Screen1} ...
0
votes
1
answer
3k
views
React routing on click event is not working [duplicate]
I am doing routing on button click event
redirect(){
return <Redirect to='/chat' />;
}
Its not working.
my home page- base component:
import React, { Fragment } from 'react';
...
0
votes
1
answer
2k
views
How to navigate to another page in react router v4 in the action [duplicate]
I am building an application that has a login screen and dashboard. When i successfully login i want my app to go to the dashboard but when i call a history.push('/dashboard'); in my ACTION(i think ...
4
votes
2
answers
487
views
How to programmatically navigate using react router [duplicate]
When using react-router I can use the Link element to create links that are natively handled by react router.
I see internally it calls this.context.transitionTo(...).
I want to do a navigation, but ...
0
votes
2
answers
1k
views
Redirect Page when login is successful [duplicate]
Below is my code for App.js and Login.js
Login page is at http://localhost:3000/login
So if user successfully login how can I redirect the user to
http://localhost:3000/home page which loads the &...
0
votes
2
answers
1k
views
Does anyone know a simple way to conditionally route to a page in next, react js, or js? [duplicate]
I have a form and I want the onSubmit function to contain a switch or an if that routes to different pages depending on form submit.
For example consider the following onSubmit function body: (but ...
9
votes
0
answers
571
views
React Router: browserHistory.push() vs this.context.router.push() [duplicate]
I've been learning React along with Redux, and have noticed two ways to change the URL programmatically (not using <Link>) when using React-Router.
One way is to push directly to browserHistory....
-1
votes
1
answer
1k
views
Redirect from a method in a React component [duplicate]
The <Redirect> tag can be used, to redirect to another route from within React render method. How can I do the same within a React component method like ?
componentDidMount ?
0
votes
1
answer
424
views
Why do we need to render a component to issue a redirect in react-router? [duplicate]
In react-router v4 we now need to use a component to redirect the user to somewhere else.
While it makes sense when building the routes component (so a route can issue a redirection), it's very odd ...
0
votes
4
answers
579
views
ReactJS: How to redirect from one route to another in react-router after XHR? [duplicate]
I'm stuck. I can't redirect my user after my request .
There is my request (in component):
const onSubmit = (data) =>{
const datafull =
{
"title": data.title,
&...
0
votes
1
answer
608
views
Whenever user opens "localhost:3000", I have to redirect the user to "localhost:3000/home/dashboard" [duplicate]
Whenever user opens localhost:3000 I have to redirect the user to localhost:3000/home/dashboard. How can I make the router to do that in a React application?
I tried but I am not getting the result I ...
1
vote
2
answers
177
views
Redirect from one page to another in react [duplicate]
I am trying to move from one-page App.js to addWork.js. I added a button to redirect the user to addWork.js in App.js but the strange thing is that the page is redirecting to the same page(App.js ...
2
votes
0
answers
112
views
Cannot find reason: React: Redirects onclick does not work but other redirects work(Link works and history.push also works) [duplicate]
All the other redirects (conditional redirects) work perfectly but not the one in the button
(using <Link> works perfectly fine)
Doesnot redirect when the button is clicked
I have implemented ...
-1
votes
1
answer
111
views
How to Perform Programmatic Navigation with react-router-dom v6? [duplicate]
I'm working on a React application and trying to implement programmatic navigation using react-router-dom v6. I want to navigate to different routes based on user interactions, such as button clicks ...