Next.js 14 在另一个页面隐藏根布局

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

我在 Next.js 14 项目中使用应用程序路由器。 我的项目文件夹结构是这样的。

-- dashboard/
              /page.tsx      # main layout is used
              /layout.tsx
              --create
                  /page.tsx      # I want to hide main layout in this page
                  /layout.tsx

layout.tsx                # main layout, used in ALL pages
         

我应该将 /dashboard/create 页面放在仪表板文件夹中。所以我想我无法将创建页面移动到另一个文件夹。

如何隐藏布局?

next.js
1个回答
0
投票

您可以将页面分隔在一个名为 ex(无布局)的单独文件夹中,并将剩余的路线放入其中(有布局),并在其中包含

layout.tx

带括号的文件夹是一种无需创建路径即可分隔代码的方法。

例如:

/dashboard
  layout.tsx                # used in ALL pages
  /(without-layout)
    /create
      page.tsx
  /(with-layout)
    layout.tsx             # used in all pages inside "(with-layout)"
    ...
© www.soinside.com 2019 - 2024. All rights reserved.