@@ -63,12 +63,11 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
63
63
*
64
64
* @return {object } $urlRouterProvider - $urlRouterProvider instance
65
65
*/
66
- this . rule =
67
- function ( rule ) {
68
- if ( ! isFunction ( rule ) ) throw new Error ( "'rule' must be a function" ) ;
69
- rules . push ( rule ) ;
70
- return this ;
71
- } ;
66
+ this . rule = function ( rule ) {
67
+ if ( ! isFunction ( rule ) ) throw new Error ( "'rule' must be a function" ) ;
68
+ rules . push ( rule ) ;
69
+ return this ;
70
+ } ;
72
71
73
72
/**
74
73
* @ngdoc object
@@ -101,16 +100,15 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
101
100
*
102
101
* @return {object } $urlRouterProvider - $urlRouterProvider instance
103
102
*/
104
- this . otherwise =
105
- function ( rule ) {
106
- if ( isString ( rule ) ) {
107
- var redirect = rule ;
108
- rule = function ( ) { return redirect ; } ;
109
- }
110
- else if ( ! isFunction ( rule ) ) throw new Error ( "'rule' must be a function" ) ;
111
- otherwise = rule ;
112
- return this ;
113
- } ;
103
+ this . otherwise = function ( rule ) {
104
+ if ( isString ( rule ) ) {
105
+ var redirect = rule ;
106
+ rule = function ( ) { return redirect ; } ;
107
+ }
108
+ else if ( ! isFunction ( rule ) ) throw new Error ( "'rule' must be a function" ) ;
109
+ otherwise = rule ;
110
+ return this ;
111
+ } ;
114
112
115
113
116
114
function handleIfMatch ( $injector , handler , match ) {
@@ -156,52 +154,49 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
156
154
* @param {string|object } what The incoming path that you want to redirect.
157
155
* @param {string|object } handler The path you want to redirect your user to.
158
156
*/
159
- this . when =
160
- function ( what , handler ) {
161
- var redirect , handlerIsString = isString ( handler ) ;
162
- if ( isString ( what ) ) what = $urlMatcherFactory . compile ( what ) ;
163
-
164
- if ( ! handlerIsString && ! isFunction ( handler ) && ! isArray ( handler ) )
165
- throw new Error ( "invalid 'handler' in when()" ) ;
157
+ this . when = function ( what , handler ) {
158
+ var redirect , handlerIsString = isString ( handler ) ;
159
+ if ( isString ( what ) ) what = $urlMatcherFactory . compile ( what ) ;
166
160
167
- var strategies = {
168
- matcher : function ( what , handler ) {
169
- if ( handlerIsString ) {
170
- redirect = $urlMatcherFactory . compile ( handler ) ;
171
- handler = [ '$match' , function ( $match ) { return redirect . format ( $match ) ; } ] ;
172
- }
173
- return extend ( function ( $injector , $location ) {
174
- return handleIfMatch ( $injector , handler , what . exec ( $location . path ( ) , $location . search ( ) ) ) ;
175
- } , {
176
- prefix : isString ( what . prefix ) ? what . prefix : ''
177
- } ) ;
178
- } ,
179
- regex : function ( what , handler ) {
180
- if ( what . global || what . sticky ) throw new Error ( "when() RegExp must not be global or sticky" ) ;
161
+ if ( ! handlerIsString && ! isFunction ( handler ) && ! isArray ( handler ) )
162
+ throw new Error ( "invalid 'handler' in when()" ) ;
181
163
182
- if ( handlerIsString ) {
183
- redirect = handler ;
184
- handler = [ '$match' , function ( $match ) { return interpolate ( redirect , $match ) ; } ] ;
185
- }
186
- return extend ( function ( $injector , $location ) {
187
- return handleIfMatch ( $injector , handler , what . exec ( $location . path ( ) ) ) ;
188
- } , {
189
- prefix : regExpPrefix ( what )
190
- } ) ;
164
+ var strategies = {
165
+ matcher : function ( what , handler ) {
166
+ if ( handlerIsString ) {
167
+ redirect = $urlMatcherFactory . compile ( handler ) ;
168
+ handler = [ '$match' , function ( $match ) { return redirect . format ( $match ) ; } ] ;
191
169
}
192
- } ;
193
-
194
- var check = { matcher : $urlMatcherFactory . isMatcher ( what ) , regex : what instanceof RegExp } ;
170
+ return extend ( function ( $injector , $location ) {
171
+ return handleIfMatch ( $injector , handler , what . exec ( $location . path ( ) , $location . search ( ) ) ) ;
172
+ } , {
173
+ prefix : isString ( what . prefix ) ? what . prefix : ''
174
+ } ) ;
175
+ } ,
176
+ regex : function ( what , handler ) {
177
+ if ( what . global || what . sticky ) throw new Error ( "when() RegExp must not be global or sticky" ) ;
195
178
196
- for ( var n in check ) {
197
- if ( check [ n ] ) {
198
- return this . rule ( strategies [ n ] ( what , handler ) ) ;
179
+ if ( handlerIsString ) {
180
+ redirect = handler ;
181
+ handler = [ '$match' , function ( $match ) { return interpolate ( redirect , $match ) ; } ] ;
199
182
}
183
+ return extend ( function ( $injector , $location ) {
184
+ return handleIfMatch ( $injector , handler , what . exec ( $location . path ( ) ) ) ;
185
+ } , {
186
+ prefix : regExpPrefix ( what )
187
+ } ) ;
200
188
}
201
-
202
- throw new Error ( "invalid 'what' in when()" ) ;
203
189
} ;
204
190
191
+ var check = { matcher : $urlMatcherFactory . isMatcher ( what ) , regex : what instanceof RegExp } ;
192
+
193
+ for ( var n in check ) {
194
+ if ( check [ n ] ) return this . rule ( strategies [ n ] ( what , handler ) ) ;
195
+ }
196
+
197
+ throw new Error ( "invalid 'what' in when()" ) ;
198
+ } ;
199
+
205
200
/**
206
201
* @ngdoc object
207
202
* @name ui.router.router.$urlRouter
@@ -234,9 +229,7 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
234
229
function check ( rule ) {
235
230
var handled = rule ( $injector , $location ) ;
236
231
237
- if ( ! handled ) {
238
- return false ;
239
- }
232
+ if ( ! handled ) return false ;
240
233
if ( isString ( handled ) ) $location . replace ( ) . url ( handled ) ;
241
234
return true ;
242
235
}
@@ -287,20 +280,15 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
287
280
location = $location . url ( ) ;
288
281
return ;
289
282
}
290
- if ( $location . url ( ) === location ) {
291
- return ;
292
- }
283
+ if ( $location . url ( ) === location ) return ;
284
+
293
285
$location . url ( location ) ;
294
286
$location . replace ( ) ;
295
287
} ,
296
288
297
289
push : function ( urlMatcher , params , options ) {
298
290
$location . url ( urlMatcher . format ( params ) ) ;
299
- options = options || { } ;
300
-
301
- if ( options . replace ) {
302
- $location . replace ( ) ;
303
- }
291
+ if ( options && options . replace ) $location . replace ( ) ;
304
292
} ,
305
293
306
294
href : function ( urlMatcher , params , options ) {
0 commit comments