Home > Article > Web Front-end > Detailed explanation of the use of angular's routing ui-router
This time I will bring you a detailed explanation of the use of angular routing ui-router. What are the precautions when using angular routing ui-router. The following is a practical case, let's take a look.
UI-router
Installation: npm install --save angular-ui-router
Configure routing status
angular.module("myApp").config(function($stateProvider,$urlRouterProvider){ $stateProvider .state({ name:'main', url:'./', template('<div>this is a main</div>') }) .state({ name:'home', url:'/home', template:'<p>this is home</p>' }) .state({ name:'about', url:'/about', template:'<h3>Welcome hello</h3>' }) //设置默认跳转 $urlRouterProvider.otherwise('/') } )
Multiple modules, multiple routes, multiple Controller Processing method
Introduction module
<script src="./angularjs/angular.js"></script> <script src="./js/ctrl1.js"></script> <script src="./js/ctrl2.js"></script> <script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>
Module dependency
var app = angular.module('myApp', ['ui.router', 'myApp.ctrl1', 'myApp.ctrl2']);
Routing configuration
app.config(function($stateProvider, $urlRouterProvider) { $stateProvider.state({ name: 'main', url: '/my', templateUrl: './test.html', controller: 'ctrl1' }) /* 1.设置一个为空匹配 url:'/my' 2. 在增加一个 路由名字前半部份相同但是后面不同的名字 * */ .state({ name:'my.page', url:'/:page' }) .state({ name: 'home', url: '/home', templateUrl: './angularjs/app.html', controller: 'ctrl2' }) .state({ name: 'about', url: '/about', template: '<div>about</div>', controller: 'ctrl3' }) $urlRouterProvider.otherwise('/') })
$stateParams Get parameters.
Inject in the controller. Can get the parameters following the address bar.
-<ui-view ui-sref=' '></ui-view>
ui-sref can be used to pass parameters
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Detailed explanation of JavaScript timer
Events and callback functions of JavaScript running mechanism
Detailed explanation of the multi-threading mechanism of the browser
The use of single-threaded JS and multi-threaded browsers
The above is the detailed content of Detailed explanation of the use of angular's routing ui-router. For more information, please follow other related articles on the PHP Chinese website!