NextJS路线在URL中显示[slug]
我有一个带有文件夹结构的NextJS应用程序:
- pages
- docs
- [slug]
- index
- [id]
- index
这些页面应该基于UI中出现的数据是动态的。这意味着用户可以转到/文档/付款/简介(其中付款和简介也是动态页面)。
但是,当用户在嵌套深处(文档/付款)中的一个级别时,一切正常,但是当用户达到2级深(例如DOC/付款/简介)时,所有链接都开始在其URL中显示[SLUG]。假设侧边栏中有一个链接,应该转到/doc/payments/payments/faq
它开始在URL中显示/docs/[slug]/faq
。 这是一个示例URL
我不知道它的发生率。
I have a NextJS app with the folder structure:
- pages
- docs
- [slug]
- index
- [id]
- index
These pages are supposed to be dynamic based on the data that appear in the UI. Meaning a user can go to /docs/payments/introduction (where payments and introduction are dynamic pages too).
However everything works fine when the user is one level deep in the nesting eg (docs/payments), but when the user goes 2 level deep (eg docs/payments/introduction), all the links begin showing [slug] in their url. Let's say there's a link in the sidebar that's supposed to go to /docs/payments/faq
it then starts showing /docs/[slug]/faq
in the url.
Here's a screenshot of an example url
I have no idea how its happening.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用
[... slug] .tsx
才能使用多个sl。如果需要更多信息,请单击在这里。
You need to use
[...slug].tsx
to be able to use multiple slugs.If you want more info, click here.
您确定正确使用
链接
s和router.push
es e e es吗?使用动态sl时,应将用作 prop。这样:或者,如果您使用
路由器
,则是这样:Are you sure you are using
Link
s androuter.push
es correctly? When using dynamic slugs, you should useas
prop. Like this:or if you are using
router
, like this: