2
2
* @coreapi
3
3
* @module url
4
4
*/ /** for typedoc */
5
- import { extend , bindFunctions , IInjectable , removeFrom } from "../common/common" ;
6
- import { isFunction , isString , isDefined , isArray } from "../common/predicates" ;
7
- import { UrlMatcher } from "./urlMatcher" ;
8
- import { services , $InjectorLike , LocationServices } from "../common/coreservices" ;
9
- import { UrlMatcherFactory } from "./urlMatcherFactory" ;
10
- import { StateParams } from "../params/stateParams" ;
11
- import { RawParams } from "../params/interface" ;
5
+ import { extend , bindFunctions , IInjectable , removeFrom } from "../common/common" ;
6
+ import { isFunction , isString , isDefined , isArray } from "../common/predicates" ;
7
+ import { UrlMatcher } from "./urlMatcher" ;
8
+ import { services , $InjectorLike , LocationServices } from "../common/coreservices" ;
9
+ import { RawParams } from "../params/interface" ;
12
10
import { Disposable } from "../interface" ;
11
+ import { UIRouter } from "../router" ;
13
12
14
13
/** @hidden Returns a string that is a prefix of all strings matching the RegExp */
15
14
function regExpPrefix ( re : RegExp ) {
@@ -32,8 +31,7 @@ function handleIfMatch($injector: $InjectorLike, $stateParams: RawParams, handle
32
31
}
33
32
34
33
/** @hidden */
35
- function appendBasePath ( url : string , isHtml5 : boolean , absolute : boolean ) : string {
36
- let baseHref = services . locationConfig . baseHref ( ) ;
34
+ function appendBasePath ( url : string , isHtml5 : boolean , absolute : boolean , baseHref : string ) : string {
37
35
if ( baseHref === '/' ) return url ;
38
36
if ( isHtml5 ) return baseHref . slice ( 0 , - 1 ) + url ;
39
37
if ( absolute ) return baseHref . slice ( 1 ) + url ;
@@ -53,15 +51,7 @@ export class UrlRouterProvider implements Disposable {
53
51
/** @hidden */
54
52
interceptDeferred = false ;
55
53
56
- /** @hidden */
57
- private $urlMatcherFactory : UrlMatcherFactory ;
58
- /** @hidden */
59
- private $stateParams : StateParams ;
60
-
61
- constructor ( $urlMatcherFactory : UrlMatcherFactory , $stateParams : StateParams ) {
62
- this . $urlMatcherFactory = $urlMatcherFactory ;
63
- this . $stateParams = $stateParams ;
64
- }
54
+ constructor ( public router : UIRouter ) { }
65
55
66
56
/** @internalapi */
67
57
dispose ( ) {
@@ -188,7 +178,8 @@ export class UrlRouterProvider implements Disposable {
188
178
* Note: the handler may also invoke arbitrary code, such as `$state.go()`
189
179
*/
190
180
when ( what : ( RegExp | UrlMatcher | string ) , handler : string | IInjectable , ruleCallback = function ( rule ) { } ) {
191
- let { $urlMatcherFactory, $stateParams} = this ;
181
+ let $urlMatcherFactory = this . router . urlMatcherFactory ;
182
+ let $stateParams = this . router . globals . params ;
192
183
let redirect , handlerIsString = isString ( handler ) ;
193
184
194
185
// @todo Queue this
@@ -282,13 +273,9 @@ export class UrlRouter implements Disposable {
282
273
private location : string ;
283
274
/** @hidden */
284
275
private listener : Function ;
285
- /** @hidden */
286
- private urlRouterProvider : UrlRouterProvider ;
287
-
288
276
289
277
/** @hidden */
290
- constructor ( urlRouterProvider : UrlRouterProvider ) {
291
- this . urlRouterProvider = urlRouterProvider ;
278
+ constructor ( public router : UIRouter ) {
292
279
bindFunctions ( UrlRouter . prototype , this , this ) ;
293
280
}
294
281
@@ -323,9 +310,11 @@ export class UrlRouter implements Disposable {
323
310
*/
324
311
sync ( evt ?) {
325
312
if ( evt && evt . defaultPrevented ) return ;
326
- let $loc = services . location ;
327
- let rules = this . urlRouterProvider . rules ;
328
- let otherwiseFn = this . urlRouterProvider . otherwiseFn ;
313
+
314
+ let router = this . router ;
315
+ let $loc = router . urlService ;
316
+ let rules = router . urlRouterProvider . rules ;
317
+ let otherwiseFn = router . urlRouterProvider . otherwiseFn ;
329
318
330
319
function check ( rule : Function ) {
331
320
let handled = rule ( services . $injector , $loc ) ;
@@ -359,7 +348,7 @@ export class UrlRouter implements Disposable {
359
348
* Internal API.
360
349
*/
361
350
update ( read ?: boolean ) {
362
- let $loc = services . location ;
351
+ let $loc = this . router . urlService ;
363
352
if ( read ) {
364
353
this . location = $loc . path ( ) ;
365
354
return ;
@@ -380,7 +369,7 @@ export class UrlRouter implements Disposable {
380
369
*/
381
370
push ( urlMatcher : UrlMatcher , params : RawParams , options : { replace ?: ( string | boolean ) } ) {
382
371
let replace = options && ! ! options . replace ;
383
- services . location . setUrl ( urlMatcher . format ( params || { } ) , replace ) ;
372
+ this . router . urlService . setUrl ( urlMatcher . format ( params || { } ) , replace ) ;
384
373
}
385
374
386
375
/**
@@ -408,13 +397,13 @@ export class UrlRouter implements Disposable {
408
397
let url = urlMatcher . format ( params ) ;
409
398
options = options || { absolute : false } ;
410
399
411
- let cfg = services . locationConfig ;
412
- let loc = services . location ;
400
+ let cfg = this . router . urlConfig ;
401
+ let loc = this . router . urlService ;
413
402
let isHtml5 = loc . html5Mode ( ) ;
414
403
if ( ! isHtml5 && url !== null ) {
415
404
url = "#" + loc . hashPrefix ( ) + url ;
416
405
}
417
- url = appendBasePath ( url , isHtml5 , options . absolute ) ;
406
+ url = appendBasePath ( url , isHtml5 , options . absolute , cfg . baseHref ( ) ) ;
418
407
419
408
if ( ! options . absolute || ! url ) {
420
409
return url ;
0 commit comments