|
@@ -1,5 +1,5 @@
|
|
|
import { useState } from 'react';
|
|
|
-import { Link } from 'react-router-dom';
|
|
|
+import { Link, NavLink } from 'react-router-dom';
|
|
|
|
|
|
const initialProducts = [
|
|
|
{
|
|
@@ -36,7 +36,20 @@ function Products() {
|
|
|
<td>{p.name}</td>
|
|
|
<td>{p.price}</td>
|
|
|
<td>
|
|
|
- <Link to={{ pathname: `/products/details/${p.id}` }}>详情</Link>
|
|
|
+ {/* 1 路由参数 在页面间传递数据 */}
|
|
|
+ {/* <Link to={{ pathname: `/products/details/${p.id}` }}>详情</Link> */}
|
|
|
+ {/* 2 查询参数 在页面间传递数据 */}
|
|
|
+ {/* <Link to={`/products/detail?pid=${p.id}`}>详情</Link> */}
|
|
|
+ {/* <Link to={{ pathname: '/products/detail', search: '?id=1' }}>
|
|
|
+ 详情
|
|
|
+ </Link> */}
|
|
|
+ {/* 3 history路由中state实现 页面间数据传递 */}
|
|
|
+ <NavLink
|
|
|
+ to={{ pathname: '/products/detail' }}
|
|
|
+ state={{ pid: p.id }}
|
|
|
+ >
|
|
|
+ 详情
|
|
|
+ </NavLink>
|
|
|
</td>
|
|
|
</tr>
|
|
|
))}
|