Home > Article > Web Front-end > Explore the simple application of ui.route in AngularJs
html page code
<body ng-app="myApp"> <div ui-view></div> <div ui-view="login"></div> <div ui-view="enroll"></div> </body>
The ui.router.js file that needs to be referenced
<script src="angular-ui-router.js"></script>
app.js
Inject UI-Router as a dependency of the web application into the main program:
url The :url option will specify a URL for the application's state based on the state in which the user is browsing the application (the address displays the link). In this way, the effect of deep linking can be achieved when browsing the application.
var myApp = angular.module('myApp', ['ui.router']); myApp.config(['$stateProvider', '$urlRouterProvider', routeConfig]); function routeConfig($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise(''); $stateProvider.state('competition', { url: '/competition', templateUrl: '/competition.html', controller: 'competitionController' }).state('competition.detail', { url: '/competition-detail', templateUrl: '/competition-detail.html', controller: 'competitionDetailController' }).state.('competition.enrollForm',{ url: '/competition.enrollForm', templateUrl: 'competition-enrollFrom.html', controller: 'enrollFromController' }).state.('competition.comments',{ url: '/competition-comments', templateUrl: 'competition-comments.html', controller: 'commentsController' }).state('competition.login',{ url: '/competition-login', views: { 'login@': { templateUrl: 'competition-login.html', controller: 'loginController' } } }).state('competition.enroll',{<br> url: '/competition-enroll',<br> views: {<br> 'enroll@': {<br><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"> templateUrl: 'competition-enroll.html',<br></em></em></em></em></em><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"> controller: 'enrollController'<br></em></em></em></em></em></em><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"> }<br></em></em></em></em></em></em></em><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"> }<br></em></em></em></em></em></em></em></em><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"><em id="__mceDel"> })<br></em></em></em></em></em></em></em></em></em><em id="__mceDel">}</em>
It should be noted that: ui.router uses $stateProvider, and ngRoute uses $routeProvider.
$state.go
$state.go(to, [,toParams],[,options])
The formal parameter to is of string type, which must be used. Use "^" or "." to indicate relative paths;
The formal parameter toParams is nullable, and the type is an object;
The formal parameter options is nullable, and the type is an object. The fields include: location is a bool type and the default is true, inherit is a bool type and the default is true, and relative is an object and the default is
$state. $current, notify is bool type and defaults to true, reload is bool type and defaults to false
$state.go('photos.detail')
$state.go('^') to the previous level, such as from photo.detail to photo
$state.go('^.list') to adjacent state, such as from photo.detail to photo.list
$state.go('^.detail.comment') to Grandchild-level state, such as from photo.detail to photo.detial.comment