我仔细阅读了下一个路由系统的文档。
它只提到我可以像这样实现动态路由:
http://localhost:3000/level1/dynamicSlug
但我正在努力实现这样的目标:
http://localhost:3000/level1/level2/dynamicSlug
我也想动态创建 level2
非常感谢 !
最佳答案
可以通过这种方式根据您的要求进行嵌套场景。
例如:
pages/
level1/
[dynamicSlug]/
- index.js // will match for /level1/1234
level2/
- index.js // will match for /level1/level2
- [dynamicSlug].js // will match for /level1/level2/1234
或者pages/
level1/
[dynamicSlug]/
- index.js // will match for /level1/1234
level2/
- index.js // will match for /level1/level2
[dynamicSlug]/
- index.js // will match for /level1/level2/1234
关于reactjs - nextjs 中的 2 级嵌套路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57648690/