Introduction to ANGULARJS Ui-router routing

Source: Internet
Author: User

Ui-router is the 3rd party route for Angular. He is not much different from ngrouter.

Ui-router can be deeply nested

Ngrouter simple nesting, needles for a single view (view is a page that needs to be nested)

For example: We clicked on a link, we need to jump to the specified page in the view, then Ngroute has met our needs, and when we click, we need to jump in different places to two different pages, Ngroute is not enough, We need to use the ui-router.

$urlRouterProvider

$urlRouterProvider is responsible for monitoring $location. When $location changes, the $urlRouterProvider starts searching through a list of rules until a matching value is found.

$urlRouterProvider the state configuration used to specify the URL on the backend.

All URLs are compiled into Urlmatcher objects.

otherwise

Defines a path to jump when the requested path is an invalid path, or loads the specified path when the first load occurs

$urlRouterProvider. Otherwise ('home');

Here is a simple demo

<script type="Text/javascript">varMyapp=angular.module ('Route',["Ui.router"]); Myapp.controller ('myctr', Function ($scope) {$scope. isActive=true; //$scope. Togg = function ($event) {//Console.log (value)//if ($event) {//$ ($event. Target). addclass ("active"); //} else {//$ ($event. Target). Removeclass ("active"); //   }          // }  }) Myapp.config (function ($stateProvider, $urlRouterProvider) {$urlRouterProvider. otherwise (' /Home'); $stateProvider. State ('Home', {URL:' /Home', Templateurl:'html/home.html'}). State ('home01', {URL:'/home01', Templateurl:'html/home01.html'}). State ('home01.list', {URL:'/list', Templateurl:'html/table.html'}). State ('Home01.pan', {URL:'/pan', Templateurl:'html/panel.html'          })      })  </script>'Route'><navclass="NavBar Navbar-default"Ng-controller='myctr'> <divclass="Container"> <ulclass="nav Navbar-nav"> <li ng-class="{true: ' active ', false: '}[isactive]"ng-click='isactive=true'><a ui-sref="Home">Home</a></li> <li ng-class="{true: ', false: ' active '}[isactive]"ng-click='Isactive=false'><a ui-sref="home01">Link</a></li> </ul> </div></nav><!--Toggle content Display--><div Ui-view style='Padding:20px;overflow:hidden'></div></div>

Introduction to ANGULARJS Ui-router routing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.