|
@@ -1,7 +1,54 @@
|
|
|
+import { useState } from "react";
|
|
|
+import { Link, useNavigate } from "react-router-dom";
|
|
|
function List() {
|
|
|
+ const navgiate = useNavigate();
|
|
|
+ const [main,setMain] = useState([
|
|
|
+ {
|
|
|
+ id:1,
|
|
|
+ name:'孙悟空',
|
|
|
+ desc:"金箍棒"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:2,
|
|
|
+ name:'哪吒',
|
|
|
+ desc:"混天绫"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id:3,
|
|
|
+ name:'猪八戒',
|
|
|
+ desc:"九齿钉耙"
|
|
|
+ }
|
|
|
+ ])
|
|
|
+ // const [name1] = useState("")
|
|
|
return (
|
|
|
<div>
|
|
|
- 列表
|
|
|
+ <h1>列表</h1>
|
|
|
+ <button onClick={()=>{
|
|
|
+ // navgiate('/')
|
|
|
+ // navgiate({
|
|
|
+ // pathname:'/'
|
|
|
+ // })
|
|
|
+ navgiate({
|
|
|
+ pathname:'/',
|
|
|
+ search:`?name=12`
|
|
|
+ },{
|
|
|
+ replace:true,
|
|
|
+ state:{
|
|
|
+ id:"12"
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }}>去首页</button>
|
|
|
+ <ul >
|
|
|
+ {
|
|
|
+ main.map((item)=><Link key={item.id} to={`/detail/${item.id}/${item.name}`}><li>{item.name}</li></Link>)
|
|
|
+ // main.map((item)=><Link key={item.id} to={{
|
|
|
+ // pathname:'/detail',
|
|
|
+ // search:`?desc=${item.name}`
|
|
|
+ // }}><li>{item.name}</li></Link>)
|
|
|
+ // main.map((item)=><Link key={item.id} to={`/detail?id=${item.id}&desc=${item.desc}`}><li>{item.name}</li></Link>)
|
|
|
+ // main.map((item)=><Link key={item.id} to={{pathname:`/detail?id=${item.id}&desc=${item.desc}`}}><li>{item.name}</li></Link>)
|
|
|
+ }
|
|
|
+ </ul>
|
|
|
</div>
|
|
|
)
|
|
|
}
|