Skip to content

Instantly share code, notes, and snippets.

@SpEcHiDe
Created June 5, 2016 07:27
Show Gist options
  • Save SpEcHiDe/9263e70d7066fa34b4bdcf043d00a647 to your computer and use it in GitHub Desktop.
Save SpEcHiDe/9263e70d7066fa34b4bdcf043d00a647 to your computer and use it in GitHub Desktop.
AngularJS : custom routes
var app = angular.module('portfolio', ['ngRoute']);
// create the controller and inject Angular's $scope
app.controller('mainController', function($scope) {
// create a message to display in our view
$scope.message = 'Everyone come and see how good I look!';
});
// configure our routes
app.config(function($routeProvider, $locationProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'partials/home.html',
controller : 'homeController'
})
.when('/404', {
templateUrl : 'partials/404.html',
controller : 'fourzerofourController'
})
$routeProvider.otherwise({redirectTo: '/404', controller: 'fourzerofourController'});
// use the HTML5 History API
$locationProvider.html5Mode({
enabled: true,
requireBase: false,
rewriteLinks: true
});
});
app.controller('homeController', function($scope) {
$scope.message = 'home -- under construction';
});
app.controller('fourzerofourController', function($scope) {
$scope.message = 'sorry, but the page you are looking for cannot be found!';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment