Skip to content

noHeadElement

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"style": {
"noHeadElement": "error"
}
}
}
}

¥Description

防止在 Next.js 项目中使用 <head> 元素。

¥Prevent usage of <head> element in a Next.js project.

Next.js 提供了一个来自 next/head 的专用 <Head /> 组件,用于管理 <head> 标签,以实现最佳的服务器端渲染、客户端导航以及自动去重 <meta><title> 等标签。

¥Next.js provides a specialized <Head /> component from next/head that manages the <head> tag for optimal server-side rendering, client-side navigation, and automatic deduplication of tags such as <meta> and <title>.

此规则仅检查 app/ 目录 之外的文件,因为 Next.js 中的处理方式通常不同。

¥This rule only checks files that are outside of the app/ directory, as it’s typically handled differently in Next.js.

¥Examples

¥Invalid

function Index() {
return (
<head>
<title>Invalid</title>
</head>
)
}
code-block.jsx:2:11 lint/style/noHeadElement ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Don’t use <head> element.

1 │ function Index() {
> 2 │ return (

> 3 │ <head>
^^^^^^
4 │ <title>Invalid</title>
5 │ </head>

Using the <head> element can cause unexpected behavior in a Next.js application. Use <Head /> from next/head instead.

¥Valid

import Head from 'next/head'
function Index() {
return (
<Head>
<title>All good!</title>
</Head>
)
}

¥Related links