简体   繁体   English

angularjs SEO友好的URL不起作用

[英]angularjs SEO friendly url does not work

I want to make my expressjs + angularjs SEO friendly and I read a lots of articles about $locationProvider. 我想使我的expressjs + angularjs SEO友好,我读了很多关于$ locationProvider的文章。 I`m using this code but my app does not run and show a blank page in the browser: 我正在使用以下代码,但我的应用无法运行,并且在浏览器中显示空白页面:

It`s my angular code: 这是我的角度代码:

var myApp = angular.module("PlannerApp" , ['ngRoute' , 'appControllers' , 'ngAnimate']);
var appControllers = angular.module('appControllers' , []);

myApp.config(['$routeProvider' , '$locationProvider' , function($routeProvider , $routeProvider){
$routeProvider.
when("/home" , 
     {templateUrl : "../home.html",
      controller: 'HomepageCtrl'
    }).
when("/about" ,
    {templateUrl : "../about.html",
      controller: 'AboutpageCtrl'
    }).
otherwise({templateUrl : "../home.html"});

$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');

}]);

function HomepageCtrl($scope) {
  $scope.$parent.seo = {
    pageTitle : 'home',
    pageDescripton: 'home We are a content heavy website so we need to be indexed.'
  };
}

function AboutpageCtrl($scope) {
  $scope.$parent.seo = {
    pageTitle : 'aboute ',
    pageDescripton: 'aboute We are a content heavy website so we need to be indexed.'
  };
}

myApp.run(function(){
   console.log("runde");
});

This is the output: 这是输出:

在此处输入图片说明

You may have to insert a base tag in your html file: 您可能需要在html文件中插入基本标记:

<head>
    <base href="/">
</head>

Source: https://stackoverflow.com/a/31098416/1005137 资料来源: https : //stackoverflow.com/a/31098416/1005137

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM