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

214
Views
No se puede leer la propiedad 'parámetros' de indefinido: no se puede obtener la identificación del producto

Estoy tratando de obtener la identificación del producto de la url usando match.params.id para pasar a la llamada api, pero está dando un error, la coincidencia devuelve indefinida es use match?.params?.id

 Cannot read property 'params' of undefined

Aplicación.js

 <Router> <Switch> <Route path={process.env.PUBLIC_URL +"/images/upload/:id"}> <UploadImages /> </Route> </Switch> </Router>

Redirigir:

 //params.id from material-ui datagrid table <LinkContainer to={`/admin-panel/home/images/upload/${params.id}`}> <button className="btn btn-primary mr-2">Set Images</button> </LinkContainer>
 const columns = [ { field: '_id', headerName: 'ID', width: 250 }, { field: 'name', headerName: 'Product Name', width: 300 }, { field: 'price', headerName: 'Price', width: 130 }, { field: 'countInStock', headerName: 'Count In Stock', width: 230 }, { field: 'createdAt', headerName: 'Date Created', width: 230 }, { field: 'action', headerName: 'Action', width: 350, renderCell: (params)=>{ return ( <div> <LinkContainer to={`/admin-panel/home/product/${params.id}/edit`}> <button className="btn btn-info mr-2">Edit</button> </LinkContainer> <LinkContainer to={`/images/upload/${params.id}`}> <button className="btn btn-primary mr-2">Set Images</button> </LinkContainer> <Button className="btn btn-danger" onClick={()=>deleteHandler(params.id)} ><Delete /></Button> </div> ) } }, ]; return ( <div className="productList" style={{height:600}} > {loading ? (<Loader />) : error ? (<Message variant="danger" >{error}</Message>):( <DataGrid rows={products} columns={columns} pageSize={10} rowsPerPageOptions={[5]} checkboxSelection /> )} </div> )

}

Cargar imágenes.js

 function UploadImages({ location, match, history }) { const productID = match.params.id return (<div></div>); }; export default UploadImages

El ID se pasa en la URL

 http://localhost:3000/images/upload/61555780c208142757be70v1
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Inicialmente, cuando se carga el componente, los params no están indefinidos. Por favor hacer esto...

 const productID = match && match.params && match.params.id;

Lo que estás haciendo arriba es esto:
Le está diciendo a reactjs que solo asigne un valor a productID después de realizar las comprobaciones de cordura en el lado derecho.

Una pista de este error:

 Cannot read property 'params' of undefined

Le dice que está intentando elegir una key llamada param de una variable undefined (en este caso match ).

Entonces, la verificación de cordura anterior significa que le está diciendo a reactjs que solo intente elegir el param si se define la match ; y solo intente elegir id si se define param .

about 4 years ago · Juan Pablo Isaza Report

0

Escribir match?.params?.id es la solución más rápida

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!