代码之家  ›  专栏  ›  技术社区  ›  bami

在“some page”中序列化从getServerSideProps返回的“something”时出错`

  •  0
  • bami  · 技术社区  · 2 年前

    我正在使用next.js进行一个项目。它有一个使用getServerSideProps的动态路由。您可以将查询传递到此页面。文件夹结构为category/[标题]。所以它接受类别/[标题]?{一些查询}URL。但当我在地址栏中键入它时,我会收到以下错误:

    enter image description here

    这是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(),但收到了同样的错误。

    0 回复  |  直到 2 年前
        1
  •  0
  •   bami    2 年前

    最后,我发现了真正的问题。我在vs代码中看到了终端中的真正错误,它拒绝了firebase的许可。getLotsInCategory和getCategories是我的firebase方法,在静态页面中非常有效,但当我使用动态页面时,我无法从firebase中获取数据。所以这个错误可以通过更改firebase配置来解决!