Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Next.js使用不同URL的动态路由_Javascript_Reactjs_Next.js_Dynamic Routing - Fatal编程技术网

Javascript Next.js使用不同URL的动态路由

Javascript Next.js使用不同URL的动态路由,javascript,reactjs,next.js,dynamic-routing,Javascript,Reactjs,Next.js,Dynamic Routing,我目前正在更新React项目以使用Next.js。我偶然发现了一个关于动态路由的小问题,到目前为止,我在网上找不到任何解决方案 我有很多信息页面,它们使用相同的组件,并根据slug显示不同的内容。使用react router可按如下方式指定: path: /:infoPage(about-us|terms|privacy|contact|faqs) /about-us, /terms, /privacy, /contact, /faqs 到目前为止,对于Next.js,我认为应该使用如下所示

我目前正在更新React项目以使用Next.js。我偶然发现了一个关于动态路由的小问题,到目前为止,我在网上找不到任何解决方案

我有很多信息页面,它们使用相同的组件,并根据slug显示不同的内容。使用
react router
可按如下方式指定:

path: /:infoPage(about-us|terms|privacy|contact|faqs)

/about-us, /terms, /privacy, /contact, /faqs
到目前为止,对于Next.js,我认为应该使用如下所示的动态路由。唯一的问题是,URL现在将具有
/infoPage/\uuuuu
-
/infoPage/about-us
/infoPage/terms

/pages
   /infoPage
      /[infoPage].js
作为解决方案,可以使用
As
和正确的URL更新链接:

<Link href="/infoPage/[infoPage]?infoPage=about-us" as="/about-us">
   <a>About Us</a>
</Link>
  • 保留
    /infoPage/[infoPage].js
    路由,将重定向从客户端/服务器添加到正确的URL

  • 我可能想得太多了,第二个解决方案不会是世界末日,但我仍然想知道是否有更好的解决方案


    提前感谢:)

    试试
    […infoPage].js
    我刚刚意识到我可以使用这些文档来定义动态路由的参数。所以我可以列出那里需要的URL。
    /pages
        /about-us.js
        /terms.js
        ...