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> 

Related Query

More Query from same tag