-->

Crawl ng-view in angular js

2019-08-30 03:23发布

问题:

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);
        });