我正在使用最新版本的 NextJs。
我有一条定义为
/app/categories/[[...subCategories]]
的路线。/app/categories/[[...subCategories]]/post/[id]
,而 post/[id]
不应该出现在包罗万象的路线中,所以我可以继续 /categories/1/2/post/1
以及 /categories/1/post/2
。
我认为这种方式不可能,但也许有更高级的方法可以做到这一点。
有人知道吗?
你是对的,这样是不可能的,你需要两个单独的动态路由:
第一个类别的包罗万象的路线
`/pages/app/categories/[[...subCategories]].js` will handle URLs like `/categories/1/2`.
然后使用特定的邮政路线
通过分离这些路线,包罗万象的内容不会干扰
/post/[id]
,您仍然可以正确访问嵌套类别和帖子。