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

150
Views
Enfrentando un problema de enrutamiento dinámico en next.js

Entonces tengo esta página dinámica en el próximo js

 import { useRouter } from 'next/router' import { WEB_RELATED, PC_EXES } from '../../components/Data'; export default function title() { const router = useRouter(); const { index } = router.query; console.log(index.length) return ( <div> </div> ) }

en esa instrucción dada.length obtengo el error -> dada no definida, traté de hacer lo mismo con el índice directamente pero me dio el mismo problema. Quiero obtener dos cadenas del parámetro de índice, ¿cómo hago eso?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe probar si el índice se define primero. Aquí hay un ejemplo de cómo lidiar con la consulta del enrutador:

PD: código disponible debajo de las imágenes

PSPS: consulte la documentación https://nextjs.org/docs/routing/dynamic-routes

ingrese la descripción de la imagen aquí

ingrese la descripción de la imagen aquí

 // pages/testStackOverflow/[index].js import React, {useEffect} from 'react'; import {useRouter} from 'next/router' const Title = () => { const router = useRouter(); const {index} = router.query // Don't use console.log directly below index because his value can be changed useEffect(() => { console.log('value', index, 'length : ', index?.length); // You can use if statement /* if(index) { doSomethingHere }*/ // Triggering router change with useEffect }, [index]) return ( <div> {index} </div> ) }; export default Title;

Espero poder ayudarte.

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!