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

148
Views
Nextjs, cómo redirigir desde _app.tsx

Estoy haciendo un enrutamiento basado en el rol del usuario en nextjs. Hice un enlace que devuelve verdadero o falso si un usuario puede navegar en una ruta. Quiero interceptar eso en el archivo _app.tsx, así que hice lo siguiente:

_app.tsx

 const App: React.FC<{ Component: React.FC; pageProps: Record<string, any>; }> = ({ Component, pageProps }) => { const router = useRouter(); const user = typeof localStorage !== 'undefined' ? (JSON.parse(localStorage.getItem('user') ?? 'null') as | User | { role: undefined }) : null; //useRouteProvider returns true/false const isUserAllowedOnRoute = useRouteProvider(router.pathname, user?.role); if (!isUserAllowedOnRoute) { window.location.replace('/'); // I also tried router.push('/') and Router.push('/') but I can't use that into this file. } return ( //... ); }; export default App;

En este caso el error es ReferenceError: window is not defined

Según el valor de isUserAllowedOnRoute , ¿cómo puedo redirigir a una ruta determinada desde aquí?

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!