小编kir*_*iri的帖子

React - TypeError:无法读取未定义的属性(读取“params”)

所以我收到一条错误消息 - TypeError: Cannot readproperties of undefined (reading 'params')

TypeError: Cannot read properties of undefined (reading 'params')
       5 | import products from '../products'
       6 | 
       7 | function ProductScreen({ match }) {
       8 |     const product = products.find((p) => p._id == match.params.id)
       9 |     return (
      10 |         <div>
      11 |             {product.name}
Run Code Online (Sandbox Code Playgroud)

这是我的 ProductScreen.js 文件,导致出现问题

import React from 'react'
import { Link } from 'react-router-dom'
import { Row, Col, Image, ListGroup, Button, Card } from 'react-bootstrap'
import Rating from '../components/Rating' …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router react-router-dom

13
推荐指数
3
解决办法
6万
查看次数

标签 统计

react-router ×1

react-router-dom ×1

reactjs ×1