当我通过硬编码的 teamName 时,会显示正确的结果,但想使用 pathParam 从 url 传递 teamName
代码:
export const TeamPage = () => {
const [team, setTeam] = useState({matches :[]});
const {teamName} = useParams();
useEffect(
()=>{
const fetchMatches = async() =>{
const response = await fetch('http://localhost:8787/team/${teamName}');
const data = await response.json();
setTeam(data);
};
fetchMatches();
},[]
);
console.log(teamName);
if(!team || !team.teamName){
return <h1>Team not found</h1>
}
return (
<div className="TeamPage">
<h1>{team.teamName}</h1>
</div>
);
}