【发布时间】:2014-01-05 03:23:13
【问题描述】:
我制作了一个单页应用程序。我已阅读以下文章create-crawlable-pushstate。 我在使用 hashbang 时遇到了问题。这对我来说似乎是一个解决方案。但我不太确定我是否能理解那里发生的事情。这是文章中的一个示例:
// We're using jQuery functions to make our lives loads easier
$('nav a').click(function(e) {
url = $(this).attr("href");
//This function would get content from the server and insert it into the id="content" element
$.getJSON("content.php", {contentid : url},function (data) {
$("#content").html(data);
});
//This is where we update the address bar with the 'url' parameter
window.history.pushState('object', 'New Title', url);
//This stops the browser from actually following the link
e.preventDefault();
}
这很好,但谷歌如何知道内容可用。 getJson 函数是异步的,所以在加载内容之前会推送状态。我的想法是在加载内容后调用 pushstate 以显示链接已准备好。
- 在我的场景中,用户单击了 href。
- 路由器捕获哈希变化并调用函数。 (我可以在内容生成后将点击事件覆盖为pushstate。
- 内容将被加载和生成。 (时间流逝)
【问题讨论】:
标签: javascript seo