score:0
one thing that you have to remember is that the redirect should be part of the returned jsx in your render method. you have to create a render method in your component. you can return in also conditionally if you want to check something before redirecting. it would look something like:
render () {
return (
<div>
{(condition) && <redirect />}
</div>)
score:1
the purpose of componentdidmount
is not to return a react element. if you want to redirect the user here, you will have to do it programmatically.
Source: stackoverflow.com
Related Query
- Can 't redirect to homepage after login whit <Redirect>
- How can I redirect a user to a user-specific homepage after login ? The user-specific url should contain the _id of the user
- How can I redirect user after they login properly?
- How can I redirect to previous page after login in react router?
- how to redirect to homepage after login in reactjs using SPA
- how to redirect to homepage after successful login in ReactJS?
- how to create login ui and user can choose role after login they redirect to rolebased dashboard in mern stack
- Automatic redirect after login with react-router
- react-redux redirect to other page after login
- Data not refreshing after login to homepage in reactjs
- Redirect to previous route after a login success
- Redirect after login React.js
- Redirect user to intended url after login Reactjs
- Redirect to Home after Login on React Redux Application
- Using React Router to Redirect to next page after successful login
- How to redirect to any url after login in redirect?
- Reactjs redirect to dashboard page after successful login with react-router-dom (v6)
- Is there an accessible way of telling that some part of UI can redirect to other page if some asynchronous condition is resolved after clicking link?
- How do i make a react app redirect to the login page after registration?
- Redirect user after login with react redux?
- React-How can I prevent going back to login page after login?
- How can i redirect to a component in react redux after returning promise (axios) . I am using react router 4
- How can I redirect a user to login when a certain link is clicked using JWT
- How to redirect back to private route after login in Next.js?
- How to create login and redirect to another page after success?
- Can't redirect after login React-Redux
- react redirect to another page after login
- How can i change name of a btn after login in react?
- How can I conditionally redirect to a page after the axios response in react?
- React - Routing & Redirect after login to attempted page
More Query from same tag
- React pass dynamic state to all routes in router
- Having trouble with submittingAnswer to Redux in react-quiz-app
- My React Router Links are not working. It's showing the url change in the browser but contents are not showing
- Guess the number in React does not display message for correct answer
- When I click the submit button, it doesn't store to the database, but it keeps redirecting back to the form page
- Converting a timer to react
- What is the different bethween using `children` elements vs using `render` func in React Router?
- React: How I can change a state variable based on the value of another state variable?
- concatenation state in useEffect cause loop
- How to pass a input field in react hooks
- NextJS - Invalid hook call. Hooks can only be called inside of the body of a function component
- React.js Context API: How to only update a value pair of an object while maintaining other pairs?
- Can you help me to get rid of this? Warning: A component is changing an uncontrolled input of type search to be controlled
- How does react render multiple pages in app.js using react-router?
- How to fix Too many re-renders. React limits the number of renders to prevent an infinite loop
- how to rerender component after amount of time
- Threejs loading font using fontloader throws and error when using React
- How can I indent every second visual row, caused by overflow wrapping, within a responsive div
- Determing if a value in an array is in the past, present or future
- How to add a CSS class when page loads and remove it when user clicks on item
- How to pass parameter to event from React Component
- On Redux: How can I change the state of a boolean within an array?
- setState on nested map break origin object structure in ReactJS
- React setState reusable
- hover in react add permanent class to DOM node
- Use React Portal to render a child into a DOM node of the parent component
- Using create-react-app and connecting it to my git repository?
- deploying officejs fabric react word add in
- Set Array of Object return empty array in React
- Convert array of objects to another structured array of objects