javascript
const [param, setParam] = useSearchParams()
const params = Object.fromEntries(param.entries());
console.log(params);
如果是params的话,就是用返回一个对象,
javascript
const p = useParams()
console.log(p);
为什么是对象?难道param还能有2个字段? 还真是!
给2个占位符
javascript
{
path: "/login/:uid/:uuid",
element: <Login />
}
javascript
<button onClick={() => navigate('/login/3/6?age=18&name=小明')}>点击</button>
打印
javascript
{
"uid": "3",
"uuid": "6"
}