33import { isFunction , isString , isDefined , isArray , isObject , extend } from "../common/common" ;
44import { IServiceProviderFactory } from "angular" ;
55import { UrlMatcher } from "./module" ;
6+ import { services } from "../common/coreservices" ;
7+ import { UrlMatcherFactory } from "./urlMatcherFactory" ;
8+ import { runtime } from "../common/angular1" ;
9+
10+ let $location = services . location ;
611
712/**
813 * @ngdoc object
@@ -20,8 +25,7 @@ import {UrlMatcher} from "./module";
2025 * There are several methods on `$urlRouterProvider` that make it useful to use directly
2126 * in your module config.
2227 */
23- $UrlRouterProvider . $inject = [ '$locationProvider' , '$urlMatcherFactoryProvider' ] ;
24- function $UrlRouterProvider ( $locationProvider , $urlMatcherFactory ) {
28+ export function $UrlRouterProvider ( $urlMatcherFactory : UrlMatcherFactory ) {
2529 var rules = [ ] , otherwise = null , interceptDeferred = false , listener ;
2630
2731 // Returns a string that is a prefix of all strings matching the RegExp
@@ -172,8 +176,8 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
172176 redirect = $urlMatcherFactory . compile ( handler ) ;
173177 handler = [ '$match' , redirect . format . bind ( redirect ) ] ;
174178 }
175- return extend ( function ( $injector , $location ) {
176- return handleIfMatch ( $injector , handler , what . exec ( $location . path ( ) , $location . search ( ) , $location . hash ( ) ) ) ;
179+ return extend ( function ( ) {
180+ return handleIfMatch ( runtime . $injector , handler , what . exec ( $location . path ( ) , $location . search ( ) , $location . hash ( ) ) ) ;
177181 } , {
178182 prefix : isString ( what . prefix ) ? what . prefix : ''
179183 } ) ;
@@ -185,8 +189,8 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
185189 redirect = handler ;
186190 handler = [ '$match' , ( $match ) => interpolate ( redirect , $match ) ] ;
187191 }
188- return extend ( function ( $injector , $location ) {
189- return handleIfMatch ( $injector , handler , what . exec ( $location . path ( ) ) ) ;
192+ return extend ( function ( ) {
193+ return handleIfMatch ( runtime . $injector , handler , what . exec ( $location . path ( ) ) ) ;
190194 } , {
191195 prefix : regExpPrefix ( what )
192196 } ) ;
@@ -262,22 +266,17 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
262266 * @ngdoc object
263267 * @name ui.router.router.$urlRouter
264268 *
265- * @requires $location
266- * @requires $rootScope
267- * @requires $injector
268- * @requires $browser
269- *
270269 * @description
271270 *
272271 */
273272 this . $get = $get ;
274- $get . $inject = [ '$location' , '$rootScope' , '$injector' , '$browser' , '$sniffer '] ;
275- function $get ( $location , $rootScope , $injector , $browser , $sniffer ) {
273+ $get . $inject = [ '$rootScope' ] ;
274+ function $get ( $rootScope ) {
276275
277276 var location = $location . url ( ) ;
278277
279278 function appendBasePath ( url , isHtml5 , absolute ) {
280- var baseHref = $browser . baseHref ( ) ;
279+ var baseHref = $location . baseHref ( ) ;
281280 if ( baseHref === '/' ) return url ;
282281 if ( isHtml5 ) return baseHref . slice ( 0 , - 1 ) + url ;
283282 if ( absolute ) return baseHref . slice ( 1 ) + url ;
@@ -289,10 +288,13 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
289288 if ( evt && evt . defaultPrevented ) return ;
290289
291290 function check ( rule ) {
292- var handled = rule ( $injector , $location ) ;
291+ var handled = rule ( runtime . $injector , $location ) ;
293292
294293 if ( ! handled ) return false ;
295- if ( isString ( handled ) ) $location . replace ( ) . url ( handled ) ;
294+ if ( isString ( handled ) ) {
295+ $location . replace ( ) ;
296+ $location . url ( handled ) ;
297+ }
296298 return true ;
297299 }
298300 var n = rules . length , i ;
@@ -390,18 +392,12 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
390392 href ( urlMatcher : UrlMatcher , params : any , options : any ) : string {
391393 if ( ! urlMatcher . validates ( params ) ) return null ;
392394
393- var isHtml5 = $locationProvider . html5Mode ( ) ;
394- if ( isObject ( isHtml5 ) ) {
395- isHtml5 = isHtml5 . enabled ;
396- }
397-
398- isHtml5 = isHtml5 && $sniffer . history ;
399-
400395 var url = urlMatcher . format ( params ) ;
401396 options = options || { } ;
402397
398+ var isHtml5 = services . location . html5Mode ( ) ;
403399 if ( ! isHtml5 && url !== null ) {
404- url = "#" + $locationProvider . hashPrefix ( ) + url ;
400+ url = "#" + $location . hashPrefix ( ) + url ;
405401 }
406402 url = appendBasePath ( url , isHtml5 , options . absolute ) ;
407403
@@ -410,12 +406,11 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) {
410406 }
411407
412408 var slash = ( ! isHtml5 && url ? '/' : '' ) , port = $location . port ( ) ;
413- port = ( port === 80 || port === 443 ? '' : ':' + port ) ;
409+ port = < any > ( port === 80 || port === 443 ? '' : ':' + port ) ;
414410
415411 return [ $location . protocol ( ) , '://' , $location . host ( ) , port , slash , url ] . join ( '' ) ;
416412 }
417413 } ;
418414 }
419415}
420416
421- angular . module ( 'ui.router.router' ) . provider ( '$urlRouter' , < IServiceProviderFactory > $UrlRouterProvider ) ;
0 commit comments