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

98
Vistas
Parameters Routing

I'm having a problem in getting the output of the "match" object value in this parameter routing code.

This is class where I use match:

import React from "react";

const ProductDetails = (props) => {
  console.log(props.match);
  return <h1>Details No. </h1>;
};

export default ProductDetails;

And the code I use for using the route is:

import React, { Component } from "react";
import NavBar from "./navbar";
import ProductDetails from "./productDetails";

class App extends Component {
  render() {
    return (
      <React.Fragment>
        <NavBar
          productsCount={this.state.Product.filter((p) => p.count > 0).length}
        />
        <main className="container">
          <Routes>
            <Route path="/about" element={<About />} />
            <Route path="/" element={<Home />} />
            <Route path="/contact" element={<Contact />} />
            <Route
              path="/cart"
              element={
                <ShoppingCart
                  products={this.state.Product}
                  onReset={this.resetData}
                  onIncrement={this.incrementEntry}
                  onDelete={this.deleteEntery}
                />
              }
            />
            <Route path="/products/:id" element={<ProductDetails />} />
          </Routes>
        </main>
      </React.Fragment>
    );
  }
}

And I get the answer as "undefined" and a lot of red errors msgs.

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

0

What is element? If you use react-router-dom for routing you must set the component for any route.

<BrowserRouter>
    <Route path ="/about" component= {<About />} />
    <Route path ="/" component= {<Home/>}/>
    <Route path ="/contact" component= {<Contact/>}/>
    <Route path ="/cart" component= {<ShoppingCart 
        products= {this.state.Product}
        onReset ={this.resetData}
        onIncrement ={this.incrementEntry} 
        onDelete = {this.deleteEntery}/>}/>
    <Route path="/products/:id" component={<ProductDetails />}/>
</BrowserRouter>
about 4 years ago · Juan Pablo Isaza Denunciar

0

if you are using react router v6 and what you want to do is getting the id, it would be:

import React from "react";

const ProductDetails = () => {
  const {id} = useParams();
  return <h1>Details No. {id}</h1>;
};

export default ProductDetails;

or if you really want the match object:

import React from "react";

const ProductDetails = () => {
  const match = useMatch();
  return <h1>Details No.</h1>;
};

export default ProductDetails;
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