如何让谷歌在Angular.js应用中索引动态标题

How to get Google to index a dynamic title in an Angular.js app

本文关键字:应用 索引 动态 标题 js Angular 谷歌      更新时间:2023-09-26

谷歌索引我的Angular.js应用程序的内容很好,也就是说,它执行JS, xhr,整个交易,但由于某种原因,标题没有正确索引,仍然是静态HTML回退(默认标题由HTML设置,JS执行之前)。

index.html我有:

<title ng-bind="title + ' &mdash; Default Title'">Default Title</title>

,当路由改变时,它是这样设置的:

app.run ['$location', '$rootScope', ($location, $rootScope) ->
    $rootScope.$on '$routeChangeSuccess', (event, current, previous) ->
      $rootScope.title = current.$$route.title if current.$$route
]

有没有人遇到过这个问题,你有解决方案吗?

对于我的angular站点,我在我的meta标签

<meta name="fragment" content="!">

这通知谷歌,这是一个ajax网站,需要重新抓取我的网站不同。它将在url的末尾添加_escaped_fragment_并重新抓取。此时,我返回带有title标记的纯html。

查看此链接:https://developers.google.com/webmasters/ajax-crawling/docs/specification