score:-1
<route exact path="/" component={template} />
read more about exact
tend to put your root route first inside <switch>
and for the last one you can have a route that will render in 404 cases.
from one of my projects
<browserrouter>
<switch>
<route exact path='/' component={home} />
<route path='/auth' component={auth} />
<route path='/dashboard' component={dahsboard} />
<route component={route404} />
</switch>
</browserrouter>
score:0
in render method
if (this.props.isloggedin) {
return <redirect to='/'/>;
}
i guess you have to import the below.
import { redirect } from 'react-router-dom'
is this what you are looking for?
score:1
make your routes like this
<switch>
<route exact path="/login" exact component={login} />
<route path="/" component={template} />
</switch>
and then in your login
component's render method
this.props.isloggedin ? <redirect to='/'/> : <div> { /* login component stuff goes here */ } </div>
Source: stackoverflow.com
Related Query
- How to redirect to home in react router dom after login with redux?
- How to add login authentication and session to ReactJS React Router and Redux with MongoDB + NodeJS Express?
- Redirect to Home after Login on React Redux Application
- How can I add multiple path for home page with react router dom 6?
- React Router with Meteor: How to remove code param from URL after redirect from OAuth without reload
- How can i redirect to a component in react redux after returning promise (axios) . I am using react router 4
- React Router Dom doesn't redirect to specified path on entering of wrong path after handling that. How do I fix it?
- How to properly set property(if user is logged) from cookie after page opens or F5 in React with router and redux
- react router dom not re-rendering after connecting the router component with redux
- React router redirect after action redux
- How to redirect from axios interceptor with react Router V4?
- How to configure webpack dev server with react router dom v4?
- How to correctly redirect after catching authentication failure with Apollo and React
- React Hooks with React Router v4 - how do I redirect to another route?
- How to scroll to top on route change with react router dom v6?
- How to test React Router params with Redux and enzyme
- React Redux with redux-observable use the router to navigate to a different page after async action complete
- Using React Router to Redirect to next page after successful login
- How to retrieve the parameter after a hash (#) with React Router and useParams hook?
- Redirect on successful login with FirebaseUI + React Router
- rerender a component after redirect with react router
- Links don't redirect with React DOM Router
- how to 'redirect' with react after login with passport.js?
- How do i make a react app redirect to the login page after registration?
- Redirect user after login with react redux?
- How to add Link from react router dom to the submit button with the default Submit validation
- react router v6 won't switch to Home Page after Login Page: Warning: Can't perform a React state update on an unmounted component
- How to unit test the output of a React component method in a React Router / Redux app with Enzyme
- How to controling browser back button with react router dom v6?
- how do I make a 404 redirect with react router 6?
More Query from same tag
- How does one specify type (typeScript) on injected properties through withRouter?
- axios post method 400 bad request
- Fetch using asysnc await inside try catch block
- api proplem and redux
- Different areas within a React component
- How can I close a Material UI Modal using an X icon rather than just by clicking outside the modal?
- How to change Yup's date format validation
- Original list doesn't show up after a search is made in planets list
- React JS template, config.json keep on minifying
- Filtering data in a list (delete button) isn't working?
- How can i create a link to an external site using a href in react.js? (using react bootstrap)
- React Save multiple images to state
- Two items are located next to each other when you hover over them appears mail or phone, ReactJS
- Wavesurfer.js is working fine, but react-wavesurfer has issues
- how to prevent re-render while using GraphQL polling
- 401 Error in React and django-rest-framework app
- Updating state with props on React child component
- How does React Strict Mode works?
- Enum index signatures in TypeScript/React
- What's the difference between aws-amplify-react and @aws-amplify/ui-react?
- React Hooks not changing state or triggering re-render
- React Icon component with SVG's
- How to properly execute logic right after setState updates the react functional component state?
- Trying to use GoogleSignIn in React Native then Possible Unhandled Promise Rejection (id: Error: DEVELOPER_ERROR
- Accessing and updating canvas node callback inside of useEffect - React
- How to render a Map in typescript
- Reactjs pass event reference to callback
- Heroku unable to start app with "npm start"
- How do I add Constructor in create-react-app?
- React: How to access the props object outside its class?