我正在努力学习下一步。正在使用getServerSideProps
计算路由。
使用免费API,我在DOM上显示了一个国家/地区列表。我希望动态链接到某个国家/地区,并获取和显示该特定国家/地区的数据。
以下是我到目前为止的代码
const Country = props => (
{props.country.name}
{props.country.capital}
);
export async function getServerSideProps(context) {
const { id } = context.query;
const res = await fetch(`https://restcountries.eu/rest/v2/name/${id}`);
const country = await res.json();
console.log(`Fetched place: ${country.name}`);
return { props: { country } };
}
export default Country;
Countries List
Countries{' '}
声明:本媒体部分图片、文章来源于网络,版权归原作者所有,如有侵权,请联系QQ:330946442删除。