MCPcopy
hub / github.com/angular-ui/ui-router / LocationHtml5Url

Function LocationHtml5Url

test/angular/1.7/angular.js:14493–14552  ·  view source on GitHub ↗

* LocationHtml5Url represents a URL * This object is exposed as $location service when HTML5 mode is enabled and supported * * @constructor * @param {string} appBase application base URL * @param {string} appBaseNoFile application base URL stripped of any filename * @param {string} basePrefix

(appBase, appBaseNoFile, basePrefix)

Source from the content-addressed store, hash-verified

14491 * @param {string} basePrefix URL path prefix
14492 */
14493function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
14494 this.$$html5 = true;
14495 basePrefix = basePrefix || '';
14496 parseAbsoluteUrl(appBase, this);
14497
14498
14499 /**
14500 * Parse given HTML5 (regular) URL string into properties
14501 * @param {string} url HTML5 URL
14502 * @private
14503 */
14504 this.$$parse = function(url) {
14505 var pathUrl = stripBaseUrl(appBaseNoFile, url);
14506 if (!isString(pathUrl)) {
14507 throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url,
14508 appBaseNoFile);
14509 }
14510
14511 parseAppUrl(pathUrl, this, true);
14512
14513 if (!this.$$path) {
14514 this.$$path = '/';
14515 }
14516
14517 this.$$compose();
14518 };
14519
14520 this.$$normalizeUrl = function(url) {
14521 return appBaseNoFile + url.substr(1); // first char is always '/'
14522 };
14523
14524 this.$$parseLinkUrl = function(url, relHref) {
14525 if (relHref && relHref[0] === '#') {
14526 // special case for links to hash fragments:
14527 // keep the old url and only replace the hash fragment
14528 this.hash(relHref.slice(1));
14529 return true;
14530 }
14531 var appUrl, prevAppUrl;
14532 var rewrittenUrl;
14533
14534
14535 if (isDefined(appUrl = stripBaseUrl(appBase, url))) {
14536 prevAppUrl = appUrl;
14537 if (basePrefix && isDefined(appUrl = stripBaseUrl(basePrefix, appUrl))) {
14538 rewrittenUrl = appBaseNoFile + (stripBaseUrl('/', appUrl) || appUrl);
14539 } else {
14540 rewrittenUrl = appBase + prevAppUrl;
14541 }
14542 } else if (isDefined(appUrl = stripBaseUrl(appBaseNoFile, url))) {
14543 rewrittenUrl = appBaseNoFile + appUrl;
14544 } else if (appBaseNoFile === url + '/') {
14545 rewrittenUrl = appBaseNoFile;
14546 }
14547 if (rewrittenUrl) {
14548 this.$$parse(rewrittenUrl);
14549 }
14550 return !!rewrittenUrl;

Callers

nothing calls this directly

Calls 5

parseAbsoluteUrlFunction · 0.70
stripBaseUrlFunction · 0.70
isStringFunction · 0.70
parseAppUrlFunction · 0.70
isDefinedFunction · 0.70

Tested by

no test coverage detected