Skip to content

Instantly share code, notes, and snippets.

@LoganArnett
Created March 6, 2015 21:07
Show Gist options
  • Save LoganArnett/be94859ff2bc7df32cb1 to your computer and use it in GitHub Desktop.
Save LoganArnett/be94859ff2bc7df32cb1 to your computer and use it in GitHub Desktop.
Basic Routing Demo for UI-Router
'use strict'
angular.module('routeApp')
.controller('AnoCtrl', function(){
console.log('Goodbye');
})
<section id="another">
<div class="another-content">
<h1 class="awesome-header">AwesomeSauce Header</h1>
<ul class="another-list">
<li class="another-item">Item 1</li>
<li class="another-item">Item 2</li>
<li class="another-item">Item 3</li>
<li class="another-item">Item 4</li>
<li class="another-item">Item 5</li>
</ul>
<a href="/main">
<h4>link back to main</h4>
</a>
<a href="/main/list">
<h4>link back to main.list</h4>
</a>
<a href="/main">
<h4>link back to main</h4>
</a>
</div>
</section>
'use strict'
angular.module('routeApp', ['ui.router'])
.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state('main', {
url: '/main',
templateUrl: 'views/main.html'
})
.state('main.list', {
url: '/list',
templateUrl: '../views/main.list.html'
})
.state('main.image', {
url: '/image',
templateUrl: '../views/main.img.html'
})
.state('another', {
url: '/another',
templateUrl: 'views/another.html',
controller: 'AnoCtrl',
controllerAs: 'ano'
})
$urlRouterProvider.otherwise('/main');
});
Install Angular UI Router or NgRoute
<!DOCTYPE html>
<html lang="en" ng-app="routeApp">
<head>
<meta charset="UTF-8">
<title>Route Demo</title>
</head>
<body ng-controller="MainCtrl as app">
<div ui-view></div>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/ui-router/release/angular-ui-router.js"></script>
<script src="app.js"></script>
<script src="controllers/main.controller.js"></script>
<script src="controllers/ano.controller.js"></script>
</body>
</html>
'use strict'
angular.module('routeApp')
.controller('MainCtrl', function(){
console.log('Hello World');
})
<section id="main">
<div class="main-content">
<h3>This is a List</h3>
<div ui-view></div>
<a href="/another">
<h4>this is a link to a new route</h4>
</a>
<a href="/main/list">
<h4>link back to main.list</h4>
</a>
<a href="/main">
<h4>link back to main</h4>
</a>
<a href="/main/image">
<h4>link back to main image</h4>
</a>
</div>
</section>
<section class="images">
<figure>
<img src="http://www.thirstyforbeer.com/db/wp-content/uploads/2013/05/ThirstyForBeer_AwesomeGIFs-0011.gif" alt="Nice">
<figcaption>AwesomePhoto</figcaption>
</figure>
</section>
<ul class="random-list">
<li class="list-item">Item 1</li>
<li class="list-item">Item 2</li>
<li class="list-item">Item 3</li>
<li class="list-item">Item 4</li>
<li class="list-item">Item 5</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment