【问题标题】:Google Search Console is not indexing my next.js Links to blog articlesGoogle Search Console 没有为我的 next.js 博客文章链接编制索引
【发布时间】:2022-12-16 08:57:10
【问题描述】:

我有一个带有博客的 next.js 网站。该博客有一个主页,其中包含从我的后端获取的所有博客文章的链接。这是页面的组件:

import { APIURL } from './../../constants'
import services from './../../components/services'
import React from 'react'
import Link from 'next/link'

class Blog extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      blog_posts: []
    }
  }

  componentDidMount = async () => {
    const response = await services.get_v2(APIURL.GET_BLOG_POSTS, {params: {}})
    if (response) {
      const blog_posts = []
      for (const post in response) {
        const blog_post = response[post]
        const blog_image = blog_post['image'] ? blog_post['image'] : '/no-image.png'
        const title_without_spaces = blog_post['title'].replace(new RegExp("\\ ","g"),'-')
        blog_posts.push(
          <Link key={'blog-post-' + post}
                href={{
                  pathname: '/blog/[title]',
                  query: { title: title_without_spaces },
                }}>
            <a className="blog-card">
              <div className="blog-title">{blog_post['title']}</div>
              <div className="blog-created">{blog_post['created_at']}</div>
            </a>
          </Link>

        )
      }
      this.setState({blog_posts: blog_posts})
    }
  }

  render () {
    return (
      <div className="home">
        <div className="home-container">
          <h1 className='blog-index-title'>
            Blog
          </h1>
          <div className="blog-index">
              {this.state.blog_posts}
          </div>
        </div>
      </div>
    )
  }
}

export default Blog

我希望每个博客的个人博文都能被谷歌抓取和索引,因为我使用的是 next.js 链接组件。然而事实并非如此。这个博客主页也得到了正确的索引,所以我不确定我现在做错了什么。我需要做什么才能让谷歌抓取这些单独的博客文章链接并将其编入索引?有什么我可以添加到站点地图以索引博客中的所有页面的东西吗?例如:

<url>
  <loc>https://www.example.io/blog/*</loc>
  <changefreq>weekly</changefreq>
  <priority>0.7</priority>
</url>

【问题讨论】:

标签: reactjs next.js google-search-console


【解决方案1】:

如果您使用 cloudflare,请尝试转为开发人员并再次测试。如果您的测试通过,您需要关闭 cloudflare 中的某些功能,例如 rocketload

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多