For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/apis/app/runtime/utility/head.md.
  • 简体中文
  • Head

    用于给 <head> 元素内添加 html 元素(如 title、meta、script 等),支持 SSR。

    使用姿势

    import { Helmet } from '@modern-js/runtime/head';
    
    export default () => <Helmet>...</Helmet>;

    示例

    import { Helmet } from '@modern-js/runtime/head';
    
    function IndexPage() {
      return (
        <div>
          <Helmet>
            <title>My page title</title>
            <meta name="viewport" content="initial-scale=1.0, width=device-width" />
          </Helmet>
          <p>Hello Modern.js!</p>
        </div>
      );
    }
    
    export default IndexPage;

    更多用法

    详见 react-helmet。