GWT? (2006)
Angular (2009)
Backbone (2010)
Knockout (2010)
Ember (2011)
Meteor (2012)
Durandal (2012)
React (2013)
<script src="angular.js"></script>
<script src="angular-route.js"></script>
<script>
angular.module( 'myApp', ['ngRoute'] );
</script>$routeProvider.when( '/manage', {
templateUrl : 'views/manage.html',
controller : 'ManageCtrl',
resolve : {
groups : ['appService', function ( appService ) {
return appService.getGroups();
}]
}
} )<a href="#/manage">Back</a>
<a ng-href="#/manage/{{group.id}}">Item 5</a>function($location) {
$location.url( '#/manage' )
}<!-- index.html -->
<html>
<head>...</head>
<body>
<header>...</header>
<div id="main">
<div ng-view></div>
</div>
<footer>...</footer>
</body>
</html>
The initial Angular router was designed to handle just a few simple cases. As Angular grew, we've slowly added more features. However, the underlying design is ill-suited to be extended much further.
It's very easy for developers to write apps that ignore URLs and break the back button with Angular. Angular should make it easier for developers to create apps with deeplinking.
Weaknesses
The ui-router library is one of the most useful that the AngularUI library gives us. It’s a routing framework that allows us to organize our interface by a state machine, rather than a simple URL route.
-- ng-newsletter (http://goo.gl/HrNqQO)
uiRouter is an alternative router for AngularJS v1.0. Instead of configuring a list of routes, you configure states. It's popular in the open source world, and solves a lot of the same problems we're aiming to solve in Angular 2.0's router.
-- Angular 2.0 Router Design Document
<script src="angular.js"></script>
<script src="angular-ui-router.js"></script>
<script>
angular.module( 'myApp', ['ui.router'] );
</script>$stateProvider.state( 'app.manage.groups', {
url : '^/manage',
views : {
'content' : {
templateUrl : 'views/manage-groups.html',
controllerAs : 'manageGroups',
controller : 'ManageGroupsCtrl'
}
}
} )If you want
Yes, you want
$stateChangeStart
$stateNotFound
$stateChangeSuccess
$stateChangeError
$viewContentLoading
$viewContentLoaded
<a ui-sref="app.manage.groups">Manage</a>
<a ui-sref="app.manage.members({id: group.id})">Edit</a>function( $state ) {
$state.go( 'app.manage.groups' );
}