已经用谷歌搜索了很久,并找到了一种改变<title>
的方法。这种方式是这样的:https://github.com/zeit/next.js/tree/master/examples/layout-component
这样做的主要问题是,每次有人刷新站点/更改页面时,标题都会从http://localhost:3000
变为实际标题(例如,关于我们),我有点害怕这是如何影响搜索引擎优化。
动态更改页面标题的正确方法是什么?
我的布局文件:
import Link from 'next/link'
import Head from './../node_modules/next/head'
export default function Layout({ children, title = 'Welcome to my website' }) {
return (
<div>
<Head>
<title>{title}</title>
</Head>
{children}
</div>
)
}
发布于 2019-07-24 05:49:05
我在我的依赖项中重新安装了"next“和"next-routes”,现在它可以工作了。
发布于 2019-07-22 22:50:30
检查next-seo并将其安装到您的next.js应用程序中。
yarn add next-seo
# or
npm install --save next-seo
它会神奇地为你处理页面标题和元描述。
import React from 'react';
import { NextSeo } from 'next-seo'; // then add the `NextSeo` at any `pages/` that you wish
export default () => (
<>
<NextSeo
title="About Us, or just any title that you wish"
description="Then with a short description here."
/>
<p>Simple Usage</p>
</>
);
在这里,我已经在我自己的web app上实现了同样的策略。
发布于 2021-10-19 06:06:32
对我来说这行得通,
从下一个导入,
import Head from 'next/head'
在return语句中,
<>
<Head>
<title>Page Title</title>
</Head>
<section>
<Your_JSX_CODE>
</section>
</>
https://stackoverflow.com/questions/57126760
复制相似问题