nextjs/no-title-in-document-head 正确性
它的作用
阻止在来自 next/document 的 Head 组件中使用 <title>。
为什么这不好?
<title> 元素应仅用于所有页面通用的任何 <head> 代码。 标题标签应改为在页面级别使用 next/head 定义。
示例
以下是此规则的错误代码示例:
javascript
import { Head } from "next/document";
export function Home() {
return (
<div>
<Head>
<title>My page title</title>
</Head>
</div>
);
}以下是此规则的正确代码示例:
javascript
import Head from "next/head";
export function Home() {
return (
<div>
<Head>
<title>My page title</title>
</Head>
</div>
);
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["nextjs"],
"rules": {
"nextjs/no-title-in-document-head": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["nextjs"],
rules: {
"nextjs/no-title-in-document-head": "error",
},
});bash
oxlint --deny nextjs/no-title-in-document-head --nextjs-plugin版本
此规则于 v0.2.0 中添加。
