You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
$location.absUrl() returns undefined with base href and html5Mode #11091
Upon loading the application, the following error is thrown n times (I believe per anchor href on the page)
2VM9729 angular.js:11607 TypeError: Cannot read property 'replace' of undefined
at trimEmptyHash (VM9729 angular.js:10564)
at $LocationProvider.$get (VM9729 angular.js:11374)
at Object.invoke (VM9729 angular.js:4185)
at VM9729 angular.js:4003
at getService (VM9729 angular.js:4144)
at Object.invoke (VM9729 angular.js:4176)
at VM9729 angular.js:4003
at getService (VM9729 angular.js:4144)
at Object.invoke (VM9729 angular.js:4176)
at VM9729 angular.js:6485
BTW, this setup of serving assets from a subdirectory but having the routes relative to root is required for our setup of having 2 separate applications running on the same domain, we just needed to differentiate the static folders from each other and don't want to include those subdirectories in every route.
This may not be a bug but would be nice to have some way of telling angular about how to map routes vs. assets
I just encountered this issue, however, I'm not using ngRoute in any fashion. My case was that the check for the base url was case sensitive and my url in the browser was lowercase, but in the base is was uppercase.
The function in question that was doing the case sensitive comparison for me was "beginsWith" in $$parseLinkUrl (there's two of those). While it may not be exactly what your case is this is where it parses the absUrl so that would be a good place to see what's happening.
function beginsWith(begin, whole) {
if (whole.indexOf(begin) === 0) {
return whole.substr(begin.length);
}
}
@SamHwang1990, that will not work if you use any app routing.
For example, if you have the following:
// From <base> href Url
baseHref = '/username/'
// From $browser.url(), what the user typed in the URL bar
initialUrl = 'http://www.example.com/UserName/additional/path/data/?queryString=something#fragment/data'
// From appBase = serverBase(initialUrl) + (baseHref || '/');
appBase = 'http://www.example.com/username/'
If you pass appBase as the first param to $$parseLinkUrl, you will lose all of the routing data, in this case additional/path/data/?queryString=something#fragment/data.
The two parameters for $$parseLinkUrl are the absolute URL and the relative URL, and in this case, since the url is from the browser (not an href link in the body) there is not relative URL so the full path is passed for both.
Same here with angular 1.3.14
Is there a workaround? Is it fixed in 1.4.0? I´m at development status so it would be ok for me to install a unstable version...
https://docs.angularjs.org/guide/$location - see the section on "Relative links" - using "/my-base" and the prior section "HTML link rewriting" example of "/not-my-base/link".
My app configured with:
<base href="Main"/>
$locationProvider.html5Mode(true);
Should be able to have <a href="https://github.com/Main/Somepage"/> that causes $location.path to change
Should be able to have <a href="https://github.com/not-my-base/Somepage"/> that causes window.location.href to change (ie: cause a browser refresh).
However when the ng-app is initializing, the routing configuration fails with error stack::
Cannot read property 'replace' of undefined
at trimEmptyHash
In Angular.js line 10551 (for version 1.3.14)
I believe I have this sorted. I'm trying to build angular from scratch to regression test a fix, but running into some issues. Will submit a pull request as soon as I get angular built and tested.
IIRC a PR was merged into master recently that initializes $$absUrl. It might take care of this. @lili21, can you check if the problem still exists on the current snapshot ?
Glad this got fixed. I would have committed the fix a long time ago, but getting an environment setup for angular contribution development proved prohibitively time consuming.
Activity
ilovett commentedon Feb 17, 2015
BTW, this setup of serving assets from a subdirectory but having the routes relative to root is required for our setup of having 2 separate applications running on the same domain, we just needed to differentiate the static folders from each other and don't want to include those subdirectories in every route.
This may not be a bug but would be nice to have some way of telling angular about how to map routes vs. assets
Feamor commentedon Feb 19, 2015
I have the same problem.
My base href is
ruWhen I run applucation by
it's all right, but when I use
(without base href) I have an exception
kindofone commentedon Mar 2, 2015
Same for me. Any response on this?
Chryssie commentedon Mar 4, 2015
I just encountered this issue, however, I'm not using ngRoute in any fashion. My case was that the check for the base url was case sensitive and my url in the browser was lowercase, but in the base is was uppercase.
The function in question that was doing the case sensitive comparison for me was "beginsWith" in $$parseLinkUrl (there's two of those). While it may not be exactly what your case is this is where it parses the absUrl so that would be a good place to see what's happening.
ilovett commentedon Mar 4, 2015
related #11223
SamHwang1990 commentedon Mar 9, 2015
it seem the bug is caused by the 814th line in file "src/ng/location.js":
$location.$$parseLinkUrl(initialUrl, initialUrl);the code above send the
initialUrlas param twice, it is weird, so i try to sendappBaseas the first param to$$parseLinkUrl, then the bug fixed.just want to know this is a correct solution?
akerfoot commentedon Mar 10, 2015
@SamHwang1990, that will not work if you use any app routing.
For example, if you have the following:
If you pass
appBaseas the first param to$$parseLinkUrl, you will lose all of the routing data, in this caseadditional/path/data/?queryString=something#fragment/data.The two parameters for
$$parseLinkUrlare the absolute URL and the relative URL, and in this case, since the url is from the browser (not an href link in the body) there is not relative URL so the full path is passed for both.akerfoot commentedon Mar 10, 2015
@Chryssie, and anyone dealing with case-sensitivity, you may want to read what I wrote over on #11223
jscontrust commentedon Mar 10, 2015
Same here with angular 1.3.14
Is there a workaround? Is it fixed in 1.4.0? I´m at development status so it would be ok for me to install a unstable version...
joelmdev commentedon Mar 13, 2015
Same issue here. Workaround is to set base path to "/" and use full url paths.
mikerains commentedon Mar 17, 2015
https://docs.angularjs.org/guide/$location - see the section on "Relative links" - using "/my-base" and the prior section "HTML link rewriting" example of "/not-my-base/link".
My app configured with:
<base href="Main"/>
$locationProvider.html5Mode(true);
Should be able to have <a href="https://github.com/Main/Somepage"/> that causes $location.path to change
Should be able to have <a href="https://github.com/not-my-base/Somepage"/> that causes window.location.href to change (ie: cause a browser refresh).
However when the ng-app is initializing, the routing configuration fails with error stack::
Cannot read property 'replace' of undefined
at trimEmptyHash
In Angular.js line 10551 (for version 1.3.14)
Also tried 1.4.x.
joelmdev commentedon Mar 19, 2015
I believe I have this sorted. I'm trying to build angular from scratch to regression test a fix, but running into some issues. Will submit a pull request as soon as I get angular built and tested.
Narretz commentedon Mar 22, 2015
That sounds great @joelmdev
Don't hesitate to ask if you have problems with the build. We always try to make it easier for people to contribute.
39 remaining items
gkalpak commentedon May 24, 2016
IIRC a PR was merged into master recently that initializes
$$absUrl. It might take care of this.@lili21, can you check if the problem still exists on the current snapshot ?
gkalpak commentedon May 24, 2016
The PR I had in mind is #14488, but it hasn't been merged yet. (Thx @Narretz for pointing it out.)
You should keep an eye on that one, @lili21.
benbr-personal commentedon May 26, 2016
@joelmdev Saved my bacon my friend, this really needs fixing.
First time I've ran into the issue and I've used HTML5Mode on lots of different apps, really need to find out whats causing it.
jdimov commentedon Jun 5, 2016
I have the same problem in last snapshot as well - AngularJS v1.5.7-build.4844+sha.cd3673e.
Is there any solution?
gkalpak commentedon Jun 6, 2016
@jdimov, the fixed is tracked at #14488.
fix($location) : initialize `$$absUrl` to empty string
jdimov commentedon Jun 6, 2016
Thanks. I think in 1.5.6 is working fine.
On Mon, Jun 6, 2016 at 3:54 PM, Georgios Kalpakas notifications@github.com
wrote:
joelmdev commentedon Jun 14, 2016
Glad this got fixed. I would have committed the fix a long time ago, but getting an environment setup for angular contribution development proved prohibitively time consuming.
Make ProtonWeb run in Electron
fix($location) : initialize `$$absUrl` to empty string