noHeadImportInDocument
¥Summary
-
规则生效日期:
v1.9.4¥Rule available since:
v1.9.4 -
诊断类别:
lint/suspicious/noHeadImportInDocument¥Diagnostic Category:
lint/suspicious/noHeadImportInDocument -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
此规则属于以下域:
¥This rule belongs to the following domains:
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "suspicious": { "noHeadImportInDocument": "error" } } }}¥Description
防止在 Next.js 项目中使用 pages/_document.js 中的 next/head 模块。
¥Prevent using the next/head module in pages/_document.js on Next.js projects.
在自定义 pages/_document.js 文件中导入 next/head 可能会导致应用出现意外行为。next/head 组件设计用于页面级别,在自定义文档中使用时,可能会干扰全局文档结构,从而导致渲染和 SEO 问题。
¥Importing next/head within the custom pages/_document.js file can cause
unexpected behavior in your application. The next/head component is designed
to be used at the page level, and when used in the custom document it can interfere
with the global document structure, which leads to issues with rendering and SEO.
要修改所有页面上的 <head> 元素,你应该使用 next/document 模块中的 <Head /> 组件。
¥To modify <head> elements across all pages, you should use the <Head />
component from the next/document module.
¥Examples
¥Valid
import Document, { Html, Head, Main, NextScript } from "next/document";
class MyDocument extends Document { static async getInitialProps(ctx) { //... }
render() { return ( <Html> <Head></Head> </Html> ); }}
export default MyDocument;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号