nextjs 中的 2 级嵌套路由 [英] 2 levels nested routing in nextjs
本文介绍了nextjs 中的 2 级嵌套路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我仔细阅读了下一个路由系统的文档.它只提到我可以像这样实现动态路由:
I carefully read the docs of next routing system. It only mentions that I could achieve dynamic routing like this:
http://localhost:3000/level1/dynamicSlug
但我正在努力实现这样的目标:
But I am trying to achive something like this:
http://localhost:3000/level1/level2/dynamicSlug
我也想动态创建 level2
And I want level2 to be created dynamic too
非常感谢!
推荐答案
通过这种方式可以根据您的要求进行嵌套场景.例如:
It is possible to do nested scenarios according to your request in this way. for example:
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
这篇关于nextjs 中的 2 级嵌套路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文