Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Redirección de React-Router después de la autenticación Obtengo un ciclo infinito de renderizaciones

Obtengo un bucle infinito cuando trato de redirigir a los usuarios a la ruta deseada después del inicio de sesión obligatorio.

Mi ruta privada, cuando agrego state: { from: props.location }, obtengo un bucle infinito.

 const PrivateRoute = ({ component: Component, exact, path, }: RouteProps): JSX.Element => { if (!Component) return <div />; const classes = useStyles(); const auth = useSelector((state: RootState) => state.auth); return ( <Route path={path} exact={exact} render={(props) => (auth.loading ? ( <Backdrop className={classes.backdrop} open> <CircularProgress color="inherit" /> </Backdrop> ) : auth.isAuthenticated ? ( <Component {...props} /> ) : ( <Redirect to={{ pathname: '/login', state: { from: props.location }, }} /> ))} /> ); };

mi interruptor

 <Router history={history}> <ThemeProvider theme={theme}> <CssBaseline /> <Alert th={ui.darkTheme} /> <UpdateApp /> <Route path="/login" exact component={Login} /> <Switch> <PrivateRoute path="/" exact component={Homepage} /> <PrivateRoute path="/info" exact component={Infos} /> <PrivateRoute path="/info/add" exact component={AddInfo} /> <PrivateRoute path="/info/:id" exact component={ShowInfo} /> <PrivateRoute path="/info/:id/edit" exact component={EditInfo} /> <PrivateRoute component={Four} /> </Switch> </ThemeProvider> </Router>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Lo resolvió con la verificación de la ruta de acceso

 const PrivateRoute = ({ component: Component, exact, path, }: RouteProps): JSX.Element => { if (!Component) return <div>ERROR</div>; const classes = useStyles(); const auth = useSelector((state: RootState) => state.auth); return ( <Route path={path} exact={exact} render={(props) => (auth.loading ? ( <Backdrop className={classes.backdrop} open> <CircularProgress color="inherit" /> </Backdrop> ) : auth.isAuthenticated ? ( <Component {...props} /> ) : (props.location.pathname !== '/login') && ( <Redirect to={{ pathname: '/login', state: { from: props.location }, }} /> ))} /> ); };
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!