我正在使用next.js进行一个项目。它有一个使用getServerSideProps的动态路由。您可以将查询传递到此页面。文件夹结构为category/[标题]。所以它接受类别/[标题]?{一些查询}URL。但当我在地址栏中键入它时,我会收到以下错误:
这是getServersideProps函数(getLotsInCategory()和getCategories()是firebase的数据获取器。他们在其他页面上工作得很好):
export async function getServerSideProps(context:any) {
let category:any=[]
let query:any
if(context.query!=undefined){
query=context.query
}
let title=context.params.title;
let lotsInCategory:any=[]
try{
console.log(query)
lotsInCategory=await getLotsInCategory(title)
if(query.subCategory!=undefined){
lotsInCategory=lotsInCategory.filter((el:any)=>query.subCategory.includes(el.subCategory)==true)
}
const categories:any=await getCategories();
category=categories.filter((el:any)=>el.categoryTitle==title)
category=category[0]
lotsInCategory= JSON.stringify(lotsInCategory)
category=JSON.stringify(category)
query=JSON.stringify(query)
}
catch(er){
console.log(er)
}
return {
props: {query,lotsInCategory,category} // will be passed to the page component as props
}
}
我尝试了.json()而不是json.stringify(),但收到了同样的错误。