【问题标题】:Prevent some components inside /pages folder to become a route in NextJS防止 /pages 文件夹内的某些组件成为 NextJS 中的路由
【发布时间】:2021-05-15 16:51:57
【问题描述】:

由于我需要 NextJS 中的 /about 路由,我创建了以下文件夹结构:

...
 |
pages/
 |
 ├── about/
       |
       ├── index.js
       |
       ├── AboutContent.jsx
 

其中AboutContent.jsx 只是帮助index.js 处理部分逻辑的组件。问题是AboutContent.jsx 变成了路由:/about/AboutContent。如何防止非 index.js 组件成为路由?

【问题讨论】:

    标签: next.js


    【解决方案1】:

    将其移出pages 文件夹。

    pages 文件夹必须只有页面组件,其余的组件可以放在src 文件夹中。

     |
    pages/
     |
     ├── about/
           |
           ├── index.js
    src/
     |
     ├── AboutContent.jsx
    

    只需从src 文件夹中导入AboutContent

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-13
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 2019-07-02
      • 2023-03-08
      • 2021-05-05
      • 1970-01-01
      相关资源
      最近更新 更多