如何将 lang 属性添加到 Next.js 中的 html 标签? [英] How to add lang attribute to html tag in Next.js?

查看:73
本文介绍了如何将 lang 属性添加到 Next.js 中的 html 标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Next.js 投资组合网站上运行了一些性能检查后,我注意到主 index.html 缺少一个 lang 属性 - 该属性作为扣除返回可访问性得分.

After running some performance check on my Next.js portfolio site I noticed that the main index.html is missing a lang attribute - which gets returned as a deduction from the accessibility score.

我可以使用 i18n 设置将语言环境添加到 next.config.js,但这些功能与 next export 不兼容 - 该站点是静态生成的.

I can add the locale by using the i18n setup to next.config.js, but those features are incompatible with next export - the site is statically generated.

Error: i18n support is not compatible with next export. See here for more info on deploying: https://nextjs.org/docs/deployment

还有其他方法可以添加lang属性吗?

Are there any other ways to add the lang attribute?

推荐答案

您可以将 lang 属性添加到 <Html> 标签"https://nextjs.org/docs/advanced-features/custom-document" rel="nofollow noreferrer">自定义_document.

You can add the lang attribute to the <Html> tag in your custom _document.

import Document, { Html, Head, Main, NextScript } from 'next/document'

class MyDocument extends Document {
  render() {
    return (
      <Html lang="en">
        <Head />
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    )
  }
}

export default MyDocument

这篇关于如何将 lang 属性添加到 Next.js 中的 html 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆