我想添加导航栏和页脚到我的nextjs项目,但我无法使用布局。这是我的文件结构。
的数据
代码如下:
import './globals.css'
import { Inter } from 'next/font/google'
import {Navbar} from '@/components/Navbar'
const inter = Inter({ subsets: ['latin'] })
export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}
export default function RootLayout({ children }) {
return (
<html lang="en">
<Navbar />
{/* hello */}
<body className={inter.className}>{children}</body>
</html>
)
}
字符串
我遇到了一个错误:
Attempted import error: 'Navbar' is not exported from '@/components/Navbar' (imported as 'Navbar').
Import trace for requested module:
./src/app/layout.js
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check your code at layout.js:15.
- error node_modules\next\dist\compiled\react-server-dom-webpack\cjs\react-server-dom-webpack-server.edge.development.js (1684:8) @ attemptResolveElement
- error Error: Unsupported Server Component type: undefined
at stringify (<anonymous>)
型
帮我解决这个问题
1条答案
按热度按时间4ngedf3f1#
您很可能忘记在Navbar.tsx中
export default
您的Navbar函数此外,导航栏组件应该在
body
内部。