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

188
Visualizações
how to get last part of pathname using useParams hook in react js

I'm trying to get the param part of this url: http://myapp.com/123 using this code:

import "./styles.css";
import { useParams } from "react-router-dom";

export default function App() {
  const { id } = useParams();
  console.log("id", id); // undefined. why??

  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>{id}</h2>
    </div>
  );
}

but somehow the id variable is undefined

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Configure a router, something like this, the 2 dots and an identifying word. path="movie/:id" or path="movie/:nameurl". Check which version of dom router you are using, you should use version 6, I have read their documentation and help. With what I said above it should be solved.

import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import GenresPage from "../pages/genres";
import Home from "../pages/home";
import Layout from "../pages/Layout";
import Movie from "../pages/movie";

export const AppRoutes = () => {
  return (
    <Router>
      <Routes>
        <Route path="/" element={<Layout />}>
          <Route index element={<Home />} />
          <Route path="movies" element={<GenresPage />} />
          <Route path="movie/:id" element={<Movie />} />
        </Route>
      </Routes>
    </Router>
  );
};
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