Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda