Routes NextJS动态URL参数和用户友好的URL';s

Routes NextJS动态URL参数和用户友好的URL';s,routes,next.js,Routes,Next.js,下面我有很多问题: 我正在我的URL上生成“字符串参数”。但是,当我创建它们时,它们就失去了用户友好的类型。例如,我的url必须是:/category/books?groups=1,2,3,4,但router.push会将其返回到:/category/books?groups=1%2C2%2C3%2C4 我的代码如下: useEffect(() => { const current_path = router.asPath const { sef } = router.

下面我有很多问题:

  • 我正在我的URL上生成“字符串参数”。但是,当我创建它们时,它们就失去了用户友好的类型。例如,我的url必须是:/category/books?groups=1,2,3,4,但router.push会将其返回到:/category/books?groups=1%2C2%2C3%2C4
  • 我的代码如下:

      useEffect(() => {
        const current_path = router.asPath
        const { sef } = router.query
        
        if(pickedProductGroup.length||pickedProductConcept.length){
          const groups = pickedProductGroup.join(',')
          const concepts = pickedProductConcept.join(',')
    
          const query = { group: groups, concept: concepts }
          const url = { pathname: '/category/[sef]', query }
          const urlAs = { pathname: '/category/' + sef, query }
    
          router.push(url, urlAs);
        }
      }, [pickedProductGroup, pickedProductConcept])
    
  • 当我更改查询字符串时,无法重新输入数据。 如果url参数发生更改,我如何每次触发它以重新加载。(当然,相同的参数应该呈现相同的html,这是必须的),但它呈现/category/book,即使我的url返回到/category/book?group=1,2,3

    导出常量getStaticProps=async(上下文)=>{ const{sef,group,concept}=context.query

       const products = await api.get(`/category/${sef}?group=${group}&concept=${concept}`)
       const web_main = await api.get('/header/web_main')
       return {
         props: {
           header_data: web_main.data.data,
           product_list: products.data.data,
           sub_categories: products.data.sub_categories,
           filters: products.data.filters,
         }
       }
     }
    

  • 请尝试为每个问题保留一个特定问题。您无法从访问查询字符串。该方法在生成时运行,并且无法访问页面请求数据。您需要
    getServerSideProps