reactjs - nextjs 中的 2 级嵌套路由

标签 reactjs next.js

我仔细阅读了下一个路由系统的文档。
它只提到我可以像这样实现动态路由:

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/

相关文章:

javascript - React.js this.props.children 的设计实践

javascript - 你如何检查 react 测试库中的复选框?

reactjs - 在更改链接时在 nextjs 中激活 a 标签

reactjs - 如何在客户端获取Next.JS环境变量?

javascript - API 数据不会在生产中更新,但在本地工作

reactjs - 如何在 React Native 的新标签页中打开外部链接?

reactjs - React - 全局使用 Bootstrap 和 css 模块

html - 如何在 react 中安全地呈现 html?

javascript - 条件链接样式 React

javascript - Next.js,如何将表单提交到另一个页面?