Car*_*arl 18 javascript frontend reactjs next.js
因此,我决定创建一个带有应用程序目录的新 Nextjs 13.4.5 项目。
我在应用程序目录中创建了一个新的仪表板目录,然后在仪表板目录中创建了页面和布局组件。它工作正常,有两个布局组件:一个是应用程序目录中的根布局,另一个是我在仪表板目录中创建的layout.tsx
最终我决定删除仪表板目录中的layout.tsx,因为我只想使用根布局,但出现错误:
./
Module not found: Can't resolve '/myproject/src/app/dashboard/layout.tsx'
https://nextjs.org/docs/messages/module-not-found
Run Code Online (Sandbox Code Playgroud)
我在我的项目中搜索了引用已删除的仪表板/layout.tsx的任何导入语句或动态导入,但没有引用
这是我的 tsconfig 文件:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": false,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Run Code Online (Sandbox Code Playgroud)
整个问题是,当您为新页面创建新目录时,如果不在该目录中创建layout.tsx,则一切正常。
但是如果您在该路由目录中创建一个布局组件然后将其删除,Nextjs 将无法在没有其布局组件的情况下渲染该路由,这有点奇怪。
有什么办法可以解决这个问题吗?因为我不想为我的路线创建一个无用的布局组件
| 归档时间: |
|
| 查看次数: |
3856 次 |
| 最近记录: |