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

187
Views
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 answers
Answer question

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