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

203
Views
Rutas protegidas en react-router-dom v6.0

Tengo una plantilla de reacción y usa react-router-dom v6.0.0 beta. Los métodos de enrutamiento son diferentes en esta versión que en las anteriores. Quiero autenticar la solicitud usando la función auth.js y mostrar la página adecuada. En react-router v5, solo tenía que envolver la ruta en el elemento <ProtectedRoute> . ¿Cómo puedo obtener el mismo resultado en este enfoque?

rutas.js

 export default function Router() { return useRoutes([ { path: '/dashboard', element: <DashboardLayout />, children: [ { path: '/', element: <Navigate to="/dashboard/app" replace /> }, { path: 'app', element: <DashboardApp /> }, ] }, { path: '/', element: <LogoOnlyLayout />, children: [ { path: 'login', element: <Login /> }, { path: 'register', element: <Register /> }, { path: '404', element: <NotFound / }, { path: '/', element: <Navigate to="/dashboard" /> }, { path: '*', element: <Navigate to="/404" /> } ] }, { path: '*', element: <Navigate to="/404" replace /> } ]); }

autenticación.js

 function ProtectedRoute({ component: Component, ...restOfProps }) { const isAuthenticated = false; return ( <Route {...restOfProps} render={(props) => isAuthenticated ? <Component {...props} /> : <Redirect to="/login" /> } /> ); } export default ProtectedRoute;

Aplicación.js

 import Router from './routes'; export default function App() { return ( <Router /> ); }
about 4 years ago · Juan Pablo Isaza
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!