Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
Facing dynamic routing problem in next.js

So i have this dynamic page in next 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>
    )
}

on that dada.length statement i get the error -> dada not defined, i tried to do the same with index directly but it gave me same problem. I want to get two strings from the index parameter how do i do that?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to test if index is defined first. Here is an example on how to deal with router query :

PS : Code available below images

PSPS : Check the documentation https://nextjs.org/docs/routing/dynamic-routes

enter image description here

enter image description here


// 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;

Hope I could help you.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda