我遇到了将数据从 next.js 中的一个页面传递到另一个页面的问题,因为我正在构建一个基本的新闻应用程序,在该应用程序中我从新闻 api 获取 get 请求,并且获得了 10 篇文章的结果,并且我正确地映射了它们,但是我想将单篇文章日期传递到名为 singleNews 的新页面。那么我该怎么做呢?这是我获取所有 10 篇文章的地方:
export default function news({data}) {
// const randomNumber = (rangeLast) => {
// return Math.floor(Math.random()*rangeLast)
// }
// console.log(data)
return (
<>
<div>
<h1 className="heading">Top Techcrunch Headlines!</h1>
</div>
<div className={styles.newsPage}>
{ // here you always have to check if the array exist by optional chaining
data.articles?.map(
(current, index) => {
return(
<Card datas={current} key={index+current.author} imageSrc={current.urlToImage} title={current.title} author={current.author}/>
)
}
)
}
</div>
</>
)
}
export async …
Run Code Online (Sandbox Code Playgroud)