Fetch As Google 显示空白页 - Reactjs

Fetch As Google Is Showing Blank Page - Reactjs

我有一个 Reactjs (v.16.6.3) 页面,它的 SEO 很重要,可以被 Google 索引。因此,我使用 Fetch as Google 工具对其进行了检查,以了解 Google-bot 从该页面呈现的内容。 但是,google 什么也没有显示,只是向我描绘了一个空白页! 我添加了 'babel-polyfill' 以满足 es6-es7-es8 要求并使 google-bot 快乐,因为我在 ComponentDidMount 中使用了 async-await (es8) 方法(以在此生命周期方法中加载异步数据)并且其他方法。虽然也使用了流行的箭头函数,但结果在 Fetch as Google 中还是什么都没有! 在导入一些仅从另一个模块导入并直接放入 render 方法(不在 componentDidMount 中)的平面数据(如我所写的以下内容)时,我什至没有得到任何结果。我已经检查并发现它们存在于 main.chunk.js 并且 Google 应该充分阅读和呈现它们但什么也没发生!

           export const sampleData01= [
                    {name: sampleName01,
                     lastName: sampleLastName01,
                     image: sampleImage01 
                     },
               {name: sampleName02,
                     lastName: sampleLastName02,
                     image: sampleImage02 
                     }

                    ]
         export const anotherData02= [
                    {name: anotherName01,
                     lastName: anotherLastName01,
                     image: anotherImage01 
                     },
               {name: anotherName02,
                     lastName: anotherLastName02,
                     image: anotherImage02 
                     }

                    ]


        -----------
        import React, {Component} from 'react'
        import {sampleData01} from './tempData'
        import Helmet from "react-helmet";
        class SampleClass extends Component {
        state = {...something , loading:false}
        async componentDidMount = ()=> {
        this.setState({loading:true})
        ...await fetch something
        this.setState({loading:false})
        }
        }

    render(){
    const data = sampleData01.map(item => {
    <li>
    {item.name}
    </li>
    }
    return (
    <div className="...">
    <Loading loading={this.state.loading}/>
    <div className="...">
    <Helmet  link={....}   title={....} meta={....}  />
    <ul>
    {data}
    </ul>
    </div>    

    </div>

    )


    }

    export default SampleClass

一切在开发和生产模式下都运行良好。我已经检查了所有可能的方法,例如 importimg es6-shim、isomorphic-fetch、url-search-params-polyfill、whatwg-fetch,但没有得到任何结果!我在一些文章中读到 google 可能会使用 phantomjs 来渲染页面。我已经在网络(不是本地)中自己检查了带有 phantomjs 的页面,它显示和呈现得非常好。我读过很多文章说 Google 搜索和 SPA 没有问题,而我却看到了其他东西!看来我应该转向 SSR,以确保拥有 SEO 友好的页面。

我尝试了很多肮脏的技巧来改善客户端呈现网站的 SEO,但最终 SSR 是唯一的选择。使用或使用 Razzle (https://github.com/jaredpalmer/razzle) or Next.js (https://github.com/zeit/next.js/)

创建您自己的 SSR 项目