Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created December 12, 2012 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrmoran/4265198 to your computer and use it in GitHub Desktop.
Save jrmoran/4265198 to your computer and use it in GitHub Desktop.
Angular.JS Routes HTML5Mode
var app = angular.module('app', []);
app.config(function($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
templateUrl: '/partials/template1.html', // <- relative to base
controller: 'ctrl1'
})
.when('/tags/:tagId', {
templateUrl: '/partials/template2.html',
controller: 'ctrl2'
})
.when('/another', {
templateUrl: '/partials/template1.html',
controller: 'ctrl1'
})
.otherwise({ redirectTo: '/' });
});
app.controller('ctrl1', function($scope){
console.log('hello ctrl1');
});
app.controller('ctrl2', function($scope){
console.log('hello ctrl2');
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Test</title>
<script src="components/angular-complete/angular.js"
type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
</head>
<body ng-app='app'>
<div>
<!-- relative to base -->
<a href="/">Home</a> |
<a href="/another">another</a> |
<a href="/tags/1">tags/1</a>
</div>
<div ng-view></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment