gpt4 book ai didi

seo - SEO 如何影响 ReactJS 页面变化

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:28:24 27 4
gpt4 key购买 nike

我正在使用一个简单的 Controller 来更改我显示的 ReactJS View ,如下所示:

    getInitialState: function() {
return {view: null};
},
setViewFromHash: function () {
var that = this;
var address = window.location.hash;
if(address != "")
{
address = address.substring(1);
require(["jsx!" + address], function (View) {
that.setState({view: View});
});
}
else
{
require(["jsx!Home"], function (View) {
that.setState({view: View});
});
}
},
componentWillMount: function () {
var that = this;
window.onhashchange = function () {
that.setViewFromHash();
};
this.setViewFromHash();
},
onTitleUpdate: function(title, canonical) {
document.title = title + titleDefault;
$('link[rel=canonical]').prop('href', canonicalDefault + canonical);
},
render: function () {
var viewToLoad = null;
if (this.state.view === null) {
viewToLoad = "Loading...";
} else {
viewToLoad = this.state.view({ onTitleUpdate: this.onTitleUpdate });
}

return (
<article>
{viewToLoad}
</article>
);
}

在我触发回调的 View 中:

var Home = React.createClass({
render: function () {
this.props.onTitleUpdate("Home", "");
...

我的问题是,此回调是否发生在有利于 SEO 的点,即页面标题和规范更改,它们是否以触发 Google 机器人意识到标题和规范已更改的方式更新?

我也在考虑使用 Cortex管理我的数据,那会更好吗?更差?没有什么不同?至于 SEO/Google 机器人对其正在查看的“页面”的看法?

最佳答案

Google 通常会保密有关何时执行 JavaScript 的详细信息;考虑 2010 年的这句话:

"For a while, we were scanning within JavaScript, and we were looking for links. Google has gotten smarter about JavaScript and can execute some JavaScript. I wouldn't say that we execute all JavaScript, so there are some conditions in which we don't execute JavaScript. Certainly there are some common, well-known JavaScript things like Google Analytics, which you wouldn't even want to execute because you wouldn't want to try to generate phantom visits from Googlebot into your Google Analytics".

总的来说,我会简单地假设 Google(当然还有其他一些搜索引擎)不会执行我的 JavaScript,这意味着我对页面所做的任何更改都不会被接受。当然,你可以简单地尝试一下,see what Google sees了解它是否有效。

无论哪种情况,React 都有能力渲染 on the server side并在客户端透明地连接其事件处理程序,使您能够轻松处理这两者。 (您可能需要重新调整一些代码以使其在两种上下文中运行。)

关于seo - SEO 如何影响 ReactJS 页面变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23024305/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com