@@ -2,7 +2,6 @@ import { JQLite } from "../../shared/jqlite/jqlite";
22import { urlResolve } from "../url-utils/url-utils" ;
33import {
44 encodeUriSegment ,
5- isBoolean ,
65 isDefined ,
76 isNumber ,
87 isObject ,
@@ -330,7 +329,6 @@ export class Location {
330329 // so the modification window is narrow.
331330 this . $$state = isUndefined ( state ) ? null : state ;
332331 this . $$urlUpdatedByLocation = true ;
333-
334332 return this ;
335333 }
336334
@@ -544,26 +542,28 @@ export class LocationHashbangUrl extends Location {
544542 }
545543}
546544
547- export function LocationProvider ( ) {
548- let hashPrefix = "!" ;
549- const html5Mode = {
550- enabled : false ,
551- requireBase : true ,
552- rewriteLinks : true ,
553- } ;
545+ export class LocationProvider {
546+ constructor ( ) {
547+ this . hashPrefixValue = "!" ;
548+ this . html5ModeConfig = {
549+ enabled : false ,
550+ requireBase : true ,
551+ rewriteLinks : true ,
552+ } ;
553+ }
554554
555555 /**
556556 * The default value for the prefix is `'!'`.
557- * @param {string= } prefix Prefix for hash part (containing path and search)
558- * @returns {* } current value if used as getter or itself (chaining) if used as setter
557+ * @param {string= } prefix - Prefix for hash part (containing path and search)
558+ * @returns {string|LocationProvider } current value if used as getter or itself (chaining) if used as setter
559559 */
560- this . hashPrefix = function ( prefix ) {
561- if ( isDefined ( prefix ) ) {
562- hashPrefix = prefix ;
560+ hashPrefix ( prefix ) {
561+ if ( typeof prefix !== "undefined" ) {
562+ this . hashPrefixValue = prefix ;
563563 return this ;
564564 }
565- return hashPrefix ;
566- } ;
565+ return this . hashPrefixValue ;
566+ }
567567
568568 /**
569569 * @param {(boolean|Object)= } mode If boolean, sets `html5Mode.enabled` to value.
@@ -585,30 +585,29 @@ export function LocationProvider() {
585585 *
586586 * @returns {Object } html5Mode object if used as getter or itself (chaining) if used as setter
587587 */
588- this . html5Mode = function ( mode ) {
589- if ( isBoolean ( mode ) ) {
590- html5Mode . enabled = mode ;
588+ html5Mode ( mode ) {
589+ if ( typeof mode === "boolean" ) {
590+ this . html5ModeConfig . enabled = mode ;
591591 return this ;
592592 }
593- if ( isObject ( mode ) ) {
594- if ( isBoolean ( mode . enabled ) ) {
595- html5Mode . enabled = mode . enabled ;
596- }
597593
598- if ( isBoolean ( mode . requireBase ) ) {
599- html5Mode . requireBase = mode . requireBase ;
600- }
601-
602- if ( isBoolean ( mode . rewriteLinks ) || isString ( mode . rewriteLinks ) ) {
603- html5Mode . rewriteLinks = mode . rewriteLinks ;
594+ if ( typeof mode === "object" ) {
595+ if ( typeof mode . enabled === "boolean" )
596+ this . html5ModeConfig . enabled = mode . enabled ;
597+ if ( typeof mode . requireBase === "boolean" )
598+ this . html5ModeConfig . requireBase = mode . requireBase ;
599+ if (
600+ typeof mode . rewriteLinks === "boolean" ||
601+ typeof mode . rewriteLinks === "string"
602+ ) {
603+ this . html5ModeConfig . rewriteLinks = mode . rewriteLinks ;
604604 }
605-
606605 return this ;
607606 }
608- return html5Mode ;
609- } ;
607+ return this . html5ModeConfig ;
608+ }
610609
611- this . $get = [
610+ $get = [
612611 "$rootScope" ,
613612 "$browser" ,
614613 "$rootElement" ,
@@ -627,8 +626,8 @@ export function LocationProvider() {
627626 const initialUrl = /** @type {string } */ ( $browser . url ( ) ) ;
628627 let appBase ;
629628
630- if ( html5Mode . enabled ) {
631- if ( ! baseHref && html5Mode . requireBase ) {
629+ if ( this . html5Mode . enabled ) {
630+ if ( ! baseHref && this . html5Mode . requireBase ) {
632631 throw $locationMinErr (
633632 "nobase" ,
634633 "$location in HTML5 mode requires a <base> tag to be present!" ,
@@ -642,7 +641,11 @@ export function LocationProvider() {
642641 }
643642 const appBaseNoFile = stripFile ( appBase ) ;
644643
645- $location = new LocationMode ( appBase , appBaseNoFile , `#${ hashPrefix } ` ) ;
644+ $location = new LocationMode (
645+ appBase ,
646+ appBaseNoFile ,
647+ `#${ this . hashPrefix } ` ,
648+ ) ;
646649 $location . $$parseLinkUrl ( initialUrl , initialUrl ) ;
647650
648651 $location . $$state = $browser . state ( ) ;
@@ -669,7 +672,7 @@ export function LocationProvider() {
669672 }
670673
671674 $rootElement . on ( "click" , ( event ) => {
672- const { rewriteLinks } = html5Mode ;
675+ const { rewriteLinks } = this . html5Mode ;
673676 // TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
674677 // currently we open nice url link and redirect then
675678
@@ -772,7 +775,7 @@ export function LocationProvider() {
772775 } ) ;
773776
774777 // update browser
775- $rootScope . $watch ( ( ) => {
778+ function browserUpdate ( ) {
776779 if ( initializing || $location . $$urlUpdatedByLocation ) {
777780 $location . $$urlUpdatedByLocation = false ;
778781
@@ -820,7 +823,9 @@ export function LocationProvider() {
820823
821824 // we don't need to return anything because $evalAsync will make the digest loop dirty when
822825 // there is a change
823- } ) ;
826+ }
827+
828+ setTimeout ( ( ) => browserUpdate ( ) ) ;
824829
825830 return $location ;
826831
@@ -832,6 +837,7 @@ export function LocationProvider() {
832837 $location . $$state ,
833838 oldState ,
834839 ) ;
840+ browserUpdate ( ) ;
835841 }
836842 } ,
837843 ] ;
0 commit comments