AngularJS routes enable you to create different URLs for different content in your application. Having different URLs for different content enables the user to bookmark URLs to specific content, and send those URLs to friends etc. In AngularJS each such bookmarkable URL is called a route.
AngularJS routes enables you to show different content depending on what route is chosen. A route is specified in the URL after the
#
sign. Thus, the following URL's all point to the same AngularJS application, but each point to different routes:http://myangularjsapp.com/index.html#books http://myangularjsapp.com/index.html#albums http://myangularjsapp.com/index.html#games http://myangularjsapp.com/index.html#apps
When the browser loads these links, the same AngularJS application will be loaded (located at
http://myangularjsapp.com/index.html
), but AngularJS will look at the route (the part of the URL after the #
) and decide what HTML template to show.
At this point it may sound a little abstract, so let us look at a fully working AngularJS route example:
<!DOCTYPE html> <html lang="en"> <head> <title>AngularJS Routes example</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular-route.min.js"></script> </head> <body ng-app="sampleApp"> <a href="#/route1/abcd">Route 1 + param</a><br/> <a href="#/route2/1234">Route 2 + param</a><br/> <div ng-view></div> <script> var module = angular.module("sampleApp", ['ngRoute']); module.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/route1/:param', { templateUrl: 'angular-route-template-1.jsp', controller: 'RouteController' }). when('/route2/:param', { templateUrl: 'angular-route-template-2.jsp', controller: 'RouteController' }). otherwise({ redirectTo: '/' }); }]); module.controller("RouteController", function($scope, $routeParams) { $scope.param = $routeParams.param; }) </script> </body> </html>
reference taken from http://tutorials.jenkov.com/angularjs/routes.html
super dude...awesome
ReplyDelete