Created
August 21, 2018 23:44
-
-
Save garoqui/98ad82a370df512f897f1f64ec2e387a to your computer and use it in GitHub Desktop.
Conditional Router React and localStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
return ( | |
<Router> | |
<div className="App"> | |
<Navigation user={this.state.user} /> | |
<div className="container"> | |
<p>{this.props.prueba}</p> | |
<Route path="/" exact strict render={ | |
()=>{ | |
return ( | |
<div className="g-form-container"> | |
<div className="g-form"> | |
<div className="fondo"> | |
<img src="http://localhost/aprendo/fotos/fondo.jpg"/> | |
</div> | |
</div> | |
</div> | |
); | |
} | |
}/> | |
<Route path="/admin" exact strict render={ | |
()=>{ | |
return (<Login/> ); | |
} | |
}/> | |
<Route path="/login" exact strict render={ | |
()=>{ | |
return (<TipoUsuario/> ); | |
} | |
}/> | |
<Route path="/loginprofesor" exact strict render={ | |
()=>{ | |
return (<LoginProfesor/> ); | |
} | |
}/> | |
<Route path="/loginalumno" exact strict render={ | |
()=>{ | |
return (<LoginAlumno/> ); | |
} | |
}/> | |
<Route path="/home/:id" exact strict render={ | |
()=>{ | |
return (<div className="g-form-container"> | |
<div className="g-form"> | |
<div className="fondo"> | |
<img src="http://localhost/aprendo/fotos/fondo.jpg"/> | |
</div> | |
</div> | |
</div> ); | |
} | |
}/> | |
<Route path="/retodetalle/:id" exact strict component={RetoDetalle}/> | |
{localStorage.getItem("role")==="1" ? <Route path="/registroprofe" exact strict render={ | |
()=>{ | |
return (<RegistroProfe areas={this.state.areas}/> ); | |
} | |
}/> : | |
<Route path="/registroprofe" exact strict render={ | |
()=>{ | |
return (<h1>Registro errado</h1> ); | |
} | |
}/>} | |
{localStorage.getItem("role")==="1" ? <Route path="/registroarea" exact strict render={ | |
()=>{ | |
return (<RegistroArea /> ); | |
} | |
}/> : | |
<Route path="/registroarea" exact strict render={ | |
()=>{ | |
return (<h1>Registro errado</h1> ); | |
} | |
}/>} | |
{localStorage.getItem("role")==="2" ? <Route path="/registrotema" exact strict render={ | |
()=>{ | |
return (<RegistroTema /> ); | |
} | |
}/> : | |
<Route path="/registrotema" exact strict render={ | |
()=>{ | |
return (<h1>Registro errado</h1> ); | |
} | |
}/>} | |
{localStorage.getItem("role")==="2" ? <Route path="/registroalumno" exact strict render={ | |
()=>{ | |
return (<RegistroAlumno grados={this.state.grados}/> ); | |
} | |
}/> : | |
<Route path="/registroalumno" exact strict render={ | |
()=>{ | |
return (<h1>Registro errado</h1> ); | |
} | |
}/>} | |
{localStorage.getItem("role")==="2" ? <Route path="/registropregunta" exact strict render={ | |
()=>{ | |
return (<RegistroPregunta temas={this.state.temas} grados={this.state.grados}/> ); | |
} | |
}/> : | |
<Route path="/registropregunta" exact strict render={ | |
()=>{ | |
return (<h1>Registro errado</h1> ); | |
} | |
}/>} | |
{localStorage.getItem("role")==="2" ? <Route path="/registrofoto" exact strict render={ | |
()=>{ | |
return (<RegistroFoto/> ); | |
} | |
}/> : | |
<Route path="/registrofoto" exact strict render={ | |
()=>{ | |
return (<h1>Registro errado</h1> ); | |
} | |
}/>} | |
{localStorage.getItem("role")==="3" ? <Route path="/retos" exact strict render={ | |
()=>{ | |
return (<Retos areas={this.state.areas}/> ); | |
} | |
}/> : | |
<Route path="/retos" exact strict render={ | |
()=>{ | |
return (<h1>Registro errado</h1> ); | |
} | |
}/>} | |
{localStorage.getItem("role")==="3" ? <Route path="/registrofotoalu" exact strict render={ | |
()=>{ | |
return (<RegistroFotoAlu/> ); | |
} | |
}/> : | |
<Route path="/registrofotoalu" exact strict render={ | |
()=>{ | |
return (<h1>Registro errado</h1> ); | |
} | |
}/>} | |
</div> | |
</div> | |
</Router> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment