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

178
Vistas
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 Respuestas
Responde la pregunta

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