aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/location.js
diff options
context:
space:
mode:
authorIgor Minar2013-08-12 10:34:01 -0700
committerIgor Minar2013-08-12 14:09:08 -0700
commitd4d34aba6efbd98050235f5b264899bb788117df (patch)
tree75d25aedfe57fa81ae13235d1eabdf6507800a32 /src/ng/location.js
parent04cebcc133c8b433a3ac5f72ed19f3631778142b (diff)
downloadangular.js-d4d34aba6efbd98050235f5b264899bb788117df.tar.bz2
fix($location): don't initialize hash url unnecessarily
After a recent refactoring using $location in the default hashbang mode would result in hash url being initialized unnecessarily in cases when the base url didn't end with a slash. for example http://localhost:8000/temp.html would get rewritten as http://location:8000/temp.html#/temp.html by error.
Diffstat (limited to 'src/ng/location.js')
-rw-r--r--src/ng/location.js22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/ng/location.js b/src/ng/location.js
index 730d2433..7b0c6ec0 100644
--- a/src/ng/location.js
+++ b/src/ng/location.js
@@ -84,6 +84,7 @@ function serverBase(url) {
* @param {string} basePrefix url path prefix
*/
function LocationHtml5Url(appBase, basePrefix) {
+ this.$$html5 = true;
basePrefix = basePrefix || '';
var appBaseNoFile = stripFile(appBase);
/**
@@ -140,7 +141,8 @@ function LocationHtml5Url(appBase, basePrefix) {
/**
* LocationHashbangUrl represents url
- * This object is exposed as $location service when html5 history api is disabled or not supported
+ * This object is exposed as $location service when developer doesn't opt into html5 mode.
+ * It also serves as the base class for html5 mode fallback on legacy browsers.
*
* @constructor
* @param {string} appBase application base URL
@@ -149,18 +151,25 @@ function LocationHtml5Url(appBase, basePrefix) {
function LocationHashbangUrl(appBase, hashPrefix) {
var appBaseNoFile = stripFile(appBase);
+ matchUrl(appBase, this);
+
+
/**
* Parse given hashbang url into properties
* @param {string} url Hashbang url
* @private
*/
this.$$parse = function(url) {
- matchUrl(url, this);
var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url);
if (!isString(withoutBaseUrl)) {
throw $locationMinErr('istart', 'Invalid url "{0}", does not start with "{1}".', url, appBase);
}
- var withoutHashUrl = withoutBaseUrl.charAt(0) == '#' ? beginsWith(hashPrefix, withoutBaseUrl) : withoutBaseUrl;
+ var withoutHashUrl = withoutBaseUrl.charAt(0) == '#'
+ ? beginsWith(hashPrefix, withoutBaseUrl)
+ : (this.$$html5)
+ ? withoutBaseUrl
+ : '';
+
if (!isString(withoutHashUrl)) {
throw $locationMinErr('nohash', 'Invalid url "{0}", missing hash prefix "{1}".', url, hashPrefix);
}
@@ -198,6 +207,7 @@ function LocationHashbangUrl(appBase, hashPrefix) {
* @param {string} hashPrefix hashbang prefix
*/
function LocationHashbangInHtml5Url(appBase, hashPrefix) {
+ this.$$html5 = true;
LocationHashbangUrl.apply(this, arguments);
var appBaseNoFile = stripFile(appBase);
@@ -221,6 +231,12 @@ LocationHashbangInHtml5Url.prototype =
LocationHtml5Url.prototype = {
/**
+ * Are we in html5 mode?
+ * @private
+ */
+ $$html5: false,
+
+ /**
* Has any change been replacing ?
* @private
*/