@@ -50,8 +50,12 @@ export class UrlRouterProvider implements Disposable {
50
50
otherwiseFn : ( $injector : $InjectorLike , $location : LocationServices ) => string ;
51
51
/** @hidden */
52
52
interceptDeferred = false ;
53
+ /** @hidden */
54
+ _router : UIRouter ;
53
55
54
- constructor ( public router : UIRouter ) { }
56
+ constructor ( router : UIRouter ) {
57
+ this . _router = router ;
58
+ }
55
59
56
60
/** @internalapi */
57
61
dispose ( ) {
@@ -178,10 +182,10 @@ export class UrlRouterProvider implements Disposable {
178
182
* Note: the handler may also invoke arbitrary code, such as `$state.go()`
179
183
*/
180
184
when ( what : ( RegExp | UrlMatcher | string ) , handler : string | IInjectable , ruleCallback = function ( rule ) { } ) {
181
- let router = this . router ;
185
+ let router = this . _router ;
182
186
let $urlMatcherFactory = router . urlMatcherFactory ;
183
187
let $stateParams = router . globals . params ;
184
- let $loc = router . urlService ;
188
+ let $url = router . urlService ;
185
189
let redirect , handlerIsString = isString ( handler ) ;
186
190
187
191
// @todo Queue this
@@ -197,7 +201,7 @@ export class UrlRouterProvider implements Disposable {
197
201
_handler = [ '$match' , redirect . format . bind ( redirect ) ] ;
198
202
}
199
203
return extend ( function ( ) {
200
- return handleIfMatch ( services . $injector , $stateParams , _handler , _what . exec ( $loc . path ( ) , $loc . search ( ) , $loc . hash ( ) ) ) ;
204
+ return handleIfMatch ( services . $injector , $stateParams , _handler , _what . exec ( $url . path ( ) , $url . search ( ) , $url . hash ( ) ) ) ;
201
205
} , {
202
206
prefix : isString ( _what . prefix ) ? _what . prefix : ''
203
207
} ) ;
@@ -210,7 +214,7 @@ export class UrlRouterProvider implements Disposable {
210
214
_handler = [ '$match' , ( $match ) => interpolate ( redirect , $match ) ] ;
211
215
}
212
216
return extend ( function ( ) {
213
- return handleIfMatch ( services . $injector , $stateParams , _handler , _what . exec ( $loc . path ( ) ) ) ;
217
+ return handleIfMatch ( services . $injector , $stateParams , _handler , _what . exec ( $url . path ( ) ) ) ;
214
218
} , {
215
219
prefix : regExpPrefix ( _what )
216
220
} ) ;
@@ -274,9 +278,12 @@ export class UrlRouter implements Disposable {
274
278
private location : string ;
275
279
/** @hidden */
276
280
private listener : Function ;
281
+ /** @hidden */
282
+ private _router : UIRouter ;
277
283
278
284
/** @hidden */
279
- constructor ( public router : UIRouter ) {
285
+ constructor ( router : UIRouter ) {
286
+ this . _router = router ;
280
287
createProxyFunctions ( UrlRouter . prototype , this , this ) ;
281
288
}
282
289
@@ -312,17 +319,17 @@ export class UrlRouter implements Disposable {
312
319
sync ( evt ?) {
313
320
if ( evt && evt . defaultPrevented ) return ;
314
321
315
- let router = this . router ;
316
- let $loc = router . urlService ;
322
+ let router = this . _router ;
323
+ let $url = router . urlService ;
317
324
let rules = router . urlRouterProvider . rules ;
318
325
let otherwiseFn = router . urlRouterProvider . otherwiseFn ;
319
326
320
327
function check ( rule : Function ) {
321
- let handled = rule ( services . $injector , $loc ) ;
328
+ let handled = rule ( services . $injector , $url ) ;
322
329
323
330
if ( ! handled ) return false ;
324
331
if ( isString ( handled ) ) {
325
- $loc . setUrl ( handled , true ) ;
332
+ $url . setUrl ( handled , true ) ;
326
333
}
327
334
return true ;
328
335
}
@@ -342,21 +349,21 @@ export class UrlRouter implements Disposable {
342
349
* This causes [[UrlRouter]] to start listening for changes to the URL, if it wasn't already listening.
343
350
*/
344
351
listen ( ) : Function {
345
- return this . listener = this . listener || this . router . urlService . onChange ( evt => this . sync ( evt ) ) ;
352
+ return this . listener = this . listener || this . _router . urlService . onChange ( evt => this . sync ( evt ) ) ;
346
353
}
347
354
348
355
/**
349
356
* Internal API.
350
357
*/
351
358
update ( read ?: boolean ) {
352
- let $loc = this . router . urlService ;
359
+ let $url = this . _router . urlService ;
353
360
if ( read ) {
354
- this . location = $loc . path ( ) ;
361
+ this . location = $url . path ( ) ;
355
362
return ;
356
363
}
357
- if ( $loc . path ( ) === this . location ) return ;
364
+ if ( $url . path ( ) === this . location ) return ;
358
365
359
- $loc . setUrl ( this . location , true ) ;
366
+ $url . setUrl ( this . location , true ) ;
360
367
}
361
368
362
369
/**
@@ -370,7 +377,7 @@ export class UrlRouter implements Disposable {
370
377
*/
371
378
push ( urlMatcher : UrlMatcher , params : RawParams , options : { replace ?: ( string | boolean ) } ) {
372
379
let replace = options && ! ! options . replace ;
373
- this . router . urlService . setUrl ( urlMatcher . format ( params || { } ) , replace ) ;
380
+ this . _router . urlService . setUrl ( urlMatcher . format ( params || { } ) , replace ) ;
374
381
}
375
382
376
383
/**
@@ -398,7 +405,7 @@ export class UrlRouter implements Disposable {
398
405
let url = urlMatcher . format ( params ) ;
399
406
options = options || { absolute : false } ;
400
407
401
- let cfg = this . router . urlService . config ;
408
+ let cfg = this . _router . urlService . config ;
402
409
let isHtml5 = cfg . html5Mode ( ) ;
403
410
if ( ! isHtml5 && url !== null ) {
404
411
url = "#" + cfg . hashPrefix ( ) + url ;
0 commit comments