我在 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 页面放在仪表板文件夹中。所以我想我无法将创建页面移动到另一个文件夹。
如何隐藏布局?
您可以将页面分隔在一个名为 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)"
...