有没有办法在NextJs中的catch-all路由之后添加额外的路由?

问题描述 投票:0回答:1

我正在使用最新版本的 NextJs。
我有一条定义为

/app/categories/[[...subCategories]]
的路线。
我希望能够拥有
/app/categories/[[...subCategories]]/post/[id]
,而
post/[id]
不应该出现在包罗万象的路线中,所以我可以继续
/categories/1/2/post/1
以及
/categories/1/post/2

我认为这种方式不可能,但也许有更高级的方法可以做到这一点。

有人知道吗?

next.js routes catch-all
1个回答
0
投票

你是对的,这样是不可能的,你需要两个单独的动态路由:

第一个类别的包罗万象的路线

`/pages/app/categories/[[...subCategories]].js` will handle URLs like `/categories/1/2`.

然后使用特定的邮政路线

通过分离这些路线,包罗万象的内容不会干扰

/post/[id]
,您仍然可以正确访问嵌套类别和帖子。

© www.soinside.com 2019 - 2024. All rights reserved.