Crawl ng-view in angular js

末鹿安然 提交于 2019-12-25 03:31:27

问题


I am developing a static website in AngularJS and I am stuck on an SEO issue. Basically my google webmasters tools tell that there are no crawl errors however when I try to fetch different routes it always returns the same home page result. It doesn't read what is injected in the ng-view div. It just shows the static text in my index.html file. The weird thing is that it actually reads my directive of the landing page '/' because when it renders it reads my navbar, footer, and content, which I have put in an "index-widget" directive but as I said it reads nothing from the ng-view directive. Any help would be appreciated. Here is the page http://luxtest.tk Thanks


回答1:


Your site is using # urls (eg http://luxtest.tk/#/kontakti) - Google bot will not see these as separate pages. You have two options:

  • enable HTML5 mode for your routes.
  • implement Google's ajax crawling process.

Switching to HTML5 mode is easier if you can set your hosting up appropriately to point all url's at the index.html page. Switching to HTML5 mode is done in the config for the app:

    angular.module('test', [])

        .config(function($locationProvider) {
            // use the HTML5 History API
            $locationProvider.html5Mode(true);
        });


来源:https://stackoverflow.com/questions/30371348/crawl-ng-view-in-angular-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!