diff --git a/public/app.js b/public/app.js index 300db72..645c196 100644 --- a/public/app.js +++ b/public/app.js @@ -1,55 +1,47 @@ -var app = angular.module('prerender-tutorial', ['ngRoute']) - .config(function($routeProvider, $locationProvider){ - $routeProvider.when('/', { - templateUrl : 'views/homeView.html', - controller: 'homeController' - }) - - $routeProvider.when('/about', { - templateUrl : '/views/aboutView.html', - controller: 'aboutController' - }) - - $routeProvider.when('/features', { - templateUrl : '/views/featuresView.html', - controller : 'featuresController' - }) - - $routeProvider.otherwise({ - redirectTo : '/' - }); - - $locationProvider.html5Mode(true); - $locationProvider.hashPrefix('!'); +angular + .module('prerender-tutorial', ['ngRoute']) + .config(function($routeProvider, $locationProvider){ + $routeProvider + .when('/', { + name: 'base', + templateUrl: 'views/homeView.html' + }) + .when('/about', { + name: 'about', + templateUrl: '/views/aboutView.html' + }) + .when('/features', { + name: 'features', + templateUrl: '/views/featuresView.html' + }) + .otherwise({ + redirectTo: '/' + }); + + $locationProvider.html5Mode(true); + $locationProvider.hashPrefix('!'); + }) + .run(function($rootScope){ + const pageMeta = { + base: { + pageTitle : 'AngularJS SEO Tutorial', + pageDescripton: 'Welcome to our tutorial on getting your AngularJS websites and apps indexed by Google.' + }, + about: { + pageTitle : 'About', + pageDescripton: 'We are a content heavy website so we need to be indexed.' + }, + features: { + pageTitle : 'Features', + pageDescripton: 'Check out some of our awesome features!' + } + }; + + $rootScope.$on('$routeChangeSuccess', function(event, current, previous){ + const route = current.$$route.name; + const pageInfo = pageMeta[route] || pageMeta.base; + + $rootScope.pageTitle = pageInfo.pageTitle; + $rootScope.pageDescription = pageInfo.pageDescription; + }); }); - -function mainController($scope) { - // We will create an seo variable on the scope and decide which fields we want to populate - $scope.seo = { - pageTitle : '', - pageDescription : '' - }; -} - -function homeController($scope) { - // For this tutorial, we will simply access the $scope.seo variable from the main controller and fill it with content. - // Additionally you can create a service to update the SEO variables - but that's for another tutorial. - $scope.$parent.seo = { - pageTitle : 'AngularJS SEO Tutorial', - pageDescripton: 'Welcome to our tutorial on getting your AngularJS websites and apps indexed by Google.' - }; -} - -function aboutController($scope) { - $scope.$parent.seo = { - pageTitle : 'About', - pageDescripton: 'We are a content heavy website so we need to be indexed.' - }; -} - -function featuresController($scope) { - $scope.$parent.seo = { - pageTitle : 'Features', - pageDescripton: 'Check out some of our awesome features!' - }; -} diff --git a/public/index.html b/public/index.html index c5b7e1d..0f26fa8 100644 --- a/public/index.html +++ b/public/index.html @@ -1,49 +1,46 @@ - + - -
+ + - -