Generating SEO-friendly URLs using HTML5 mode

All this while, all the URLs in our AngularJS app have had # in the URLs. When building a CMS, ensuring that the URLs are meaningful and SEO-friendly is quite important.

To make our site URLs are SEO friendly, we need to turn on the HTML5 mode in $locationProvider by making the following highlighted changes in the angcms/public/js/app.js file:

.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
  $routeProvider.when('/view1', {templateUrl: 'partials/partial1.html', controller: 'MyCtrl1'});
  $routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'});
  $routeProvider.otherwise({redirectTo: '/view1'});
 $locationProvider.html5Mode(true); ...

Get AngularJS Web Application Development Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.