<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

      <route exact path='/' component={home} />
      <route path='/auth' component={auth} />
      <route path='/dashboard' component={dahsboard} />
      <route component={route404} />


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?


make your routes like this

      <route exact path="/login" exact component={login} />
      <route path="/" component={template} />

and then in your login component's render method

this.props.isloggedin ? <redirect to='/'/> : <div> { /* login component stuff goes here */ } </div> 

Related Query

More Query from same tag