Product.jsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { useState } from "react";
  2. import "./Product.css";
  3. import { Link } from "react-router-dom";
  4. const newList = [
  5. {
  6. id: 11,
  7. name: "孙悟空",
  8. desc: "我家住在花果山",
  9. },
  10. {
  11. id: 22,
  12. name: "胡图图",
  13. desc: "我家住在翻斗花园",
  14. },
  15. {
  16. id: 33,
  17. name: "喜羊羊",
  18. desc: "我家住在青青草原",
  19. },
  20. ];
  21. function Product() {
  22. let [list] = useState(newList);
  23. return (
  24. <>
  25. <table border={1} cellPadding={15}>
  26. <thead>
  27. <tr>
  28. <th>姓名</th>
  29. <th>描述</th>
  30. <th>操作</th>
  31. </tr>
  32. </thead>
  33. <tbody>
  34. {list.map((item, index) => (
  35. <tr key={index}>
  36. <td>{item.name}</td>
  37. <td>{item.desc}</td>
  38. <td>
  39. {/*页面跳转伴随着参数的传递 参数传递? */}
  40. {/*1.路由传参 动态路由 跳转*/}
  41. {/* <Link to={{ pathname: `/product/detail/${item.id}` }}>去详情</Link> */}
  42. {/* 2.查询参数 */}
  43. {/* <Link to={`/product/detail?productId=${item.id}`}>去详情</Link> */}
  44. {/* <Link to={{pathname:'/product/detail',search:`?productId=${item.id}`}}>去详情</Link> */}
  45. {/* 3.history 中路由传参 state传参*/}
  46. <Link to={{pathname:"/product/detail"}} state={{productId: item.id}}>去详情</Link>
  47. </td>
  48. </tr>
  49. ))}
  50. </tbody>
  51. </table>
  52. </>
  53. );
  54. }
  55. export default Product;