跳到內容
文件錯誤沒有 Head 元素

沒有 Head 元素

防止使用 <head> 元素。

為何發生此錯誤

使用了 <head> 元素來包含頁面層級的 metadata,但這可能會在 Next.js 應用程式中造成非預期的行為。請改用 Next.js 內建的 next/head 元件。

可能的修正方式

匯入並使用 <Head /> 元件

pages/index.js
import Head from 'next/head'
 
function Index() {
  return (
    <>
      <Head>
        <title>My page title</title>
        <meta name="viewport" content="initial-scale=1.0, width=device-width" />
      </Head>
    </>
  )
}
 
export default Index