44 */ /** */
55import { LocationConfig , LocationServices , UIRouter , ParamType , isDefined } from '@uirouter/core' ;
66import { val , createProxyFunctions , removeFrom , isObject } from '@uirouter/core' ;
7- import { ILocationService , ILocationProvider } from 'angular' ;
7+ import { ILocationService , ILocationProvider , IWindowService } from 'angular' ;
88
99/**
1010 * Implements UI-Router LocationServices and LocationConfig using Angular 1's $location service
1111 */
1212export class Ng1LocationServices implements LocationConfig , LocationServices {
1313 private $locationProvider : ILocationProvider ;
1414 private $location : ILocationService ;
15- private $sniffer ;
15+ private $sniffer : any ;
16+ private $browser : any ;
17+ private $window : IWindowService ;
1618
1719 path ;
1820 search ;
@@ -21,7 +23,8 @@ export class Ng1LocationServices implements LocationConfig, LocationServices {
2123 port ;
2224 protocol ;
2325 host ;
24- baseHref ;
26+
27+ private _baseHref : string ;
2528
2629 // .onChange() registry
2730 private _urlListeners : Function [ ] = [ ] ;
@@ -67,27 +70,30 @@ export class Ng1LocationServices implements LocationConfig, LocationServices {
6770 return html5Mode && this . $sniffer . history ;
6871 }
6972
73+ baseHref ( ) {
74+ return this . _baseHref || ( this . _baseHref = this . $browser . baseHref ( ) || this . $window . location . pathname ) ;
75+ }
76+
7077 url ( newUrl ?: string , replace = false , state ?) {
7178 if ( isDefined ( newUrl ) ) this . $location . url ( newUrl ) ;
7279 if ( replace ) this . $location . replace ( ) ;
7380 if ( state ) this . $location . state ( state ) ;
7481 return this . $location . url ( ) ;
7582 }
7683
77- _runtimeServices ( $rootScope , $location : ILocationService , $sniffer , $browser ) {
84+ _runtimeServices ( $rootScope , $location : ILocationService , $sniffer , $browser , $window : IWindowService ) {
7885 this . $location = $location ;
7986 this . $sniffer = $sniffer ;
87+ this . $browser = $browser ;
88+ this . $window = $window ;
8089
8190 // Bind $locationChangeSuccess to the listeners registered in LocationService.onChange
8291 $rootScope . $on ( '$locationChangeSuccess' , evt => this . _urlListeners . forEach ( fn => fn ( evt ) ) ) ;
8392 const _loc = val ( $location ) ;
84- const _browser = val ( $browser ) ;
8593
8694 // Bind these LocationService functions to $location
8795 createProxyFunctions ( _loc , this , _loc , [ 'replace' , 'path' , 'search' , 'hash' ] ) ;
8896 // Bind these LocationConfig functions to $location
8997 createProxyFunctions ( _loc , this , _loc , [ 'port' , 'protocol' , 'host' ] ) ;
90- // Bind these LocationConfig functions to $browser
91- createProxyFunctions ( _browser , this , _browser , [ 'baseHref' ] ) ;
9298 }
9399}
0 commit comments