-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$location.absUrl() returns undefined with base href and html5Mode #11091
Comments
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 have the same problem. My base href is When I run applucation by
it's all right, but when I use
(without base href) I have an exception
|
The same for me, also with Angular 1.3.14 |
Same for me. Any response on this? |
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.
|
related #11223 |
it seem the bug is caused by the 814th line in file "src/ng/location.js": the code above send the just want to know this is a correct solution? |
@SamHwang1990, that will not work if you use any app routing. For example, if you have the following:
If you pass The two parameters for |
Same here with angular 1.3.14 |
Same issue here. Workaround is to set base path to "/" and use full url paths. |
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: Should be able to have <a href="/Main/Somepage"/> that causes $location.path to change However when the ng-app is initializing, the routing configuration fails with error stack:: Also tried 1.4.x. |
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. |
That sounds great @joelmdev |
Same thing here.
Has someone already solved that? |
@Narretz I wasted a lot of time trying to get everything to build on Windows and ultimately had to go with an Ubuntu VM. Still working out some bugs with the VM, but I got Angular to build and the unit tests to run. I may need some assistance on creating an e2e test to cover the fix. Any pointers on where I can go to get some advice on that? |
@joelmdev |
I have this problem also. Can the fix be shared until an updated release is made? |
starting at line 10811, replace var locationPrototype = {
/**
* Are we in html5 mode?
* @private
*/
$$html5: false, with var locationPrototype = {
/**
* Ensure absolute url is initialized.
* @private
*/
$$absUrl:'',
/**
* Are we in html5 mode?
* @private
*/
$$html5: false, @Narretz I believe this fix requires an integration test, I don't see how to isolate it enough for a unit test. Would you agree? |
@joelmdev |
I'll submit a pull request sometime this week and see where it gets me. |
This appears to be fixed, perhaps inadvertently, in the latest version available via Nuget. Can someone else verify? |
Still have this in 1.4.1. |
Still seeing this issue in 1.4.1 and installed |
Running into this as well. So dang frustrating. |
I'm almost embarrassed to offer this hack as a workaround solution to this problem, but I'm finding it useful so far and thought that it might benefit someone here. If before you load angular onto the page, you put
then angular will be fooled into thinking that there is no base tag at all. And then the error referenced in this issue does not happen. Completely ignoring the base tag may or may not be what you really want in the end, but if it is then this works :p |
@joeldenning I'll give this a shot. If this fixes the problem until my fix is committed and approved, then it's a great workaround. I'm having to keep custom copies of angular source in my repo instead of letting a package manager restore them for me as well as apply the same fix in place whenever updates are released. I know that the fix I provided has worked for everyone that has tried it and doesn't seem to cause any regression bugs, but I'm just not familiar enough with Angular testing to provide the necessary test coverage to submit the change as a pull request. |
I am using angular 1.4.3. The issue for my case is base tag case sensitive. My application is base on server side MVC, thus I have ability to change base tag value base on query URL. Thus resolved issue. Challenge is angular base route is case sensitive while my server is case insensitive. |
@Nness set route to be case insensitive: caseInsensitiveMatch: true https://docs.angularjs.org/api/ngRoute/provider/$routeProvider |
I'm using ui-router not ngRoute. That config is no use. Take look the issue under uirouter: |
@joelmdev I have used "/demo/" as my base URL and I was tried to access my app using "www.domainname.com" got the error. The error is gone when I access the app using the URL "www.domainname.com/demo". This could help someone. |
Wondering if this is related to the issue I'm having currently.
returns a value in Chrome but not in IE. I'm using a base url and html5 mode. |
… undefined with base href and html5Mode
…html5Mode $location's absUrl incorrectly returned undefined when using base href and html5Mode. Initializaing it to fix this issue. Closes angular#11091
… undefined with base href and html5Mode
(Almost) The same as codedbypaul here,
Returns a correct value in Chrome but not Firefox |
still have this in 1.5.5. any plan about this issue? |
@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. |
I have the same problem in last snapshot as well - AngularJS v1.5.7-build.4844+sha.cd3673e. |
Thanks. I think in 1.5.6 is working fine. On Mon, Jun 6, 2016 at 3:54 PM, Georgios Kalpakas [email protected]
|
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. |
Few changes were required to make it happen: 1. base url must point to ./ and all asset refrences must use relative paths. 2. Angular must be updated to 1.5.10 due to this bug angular/angular.js#11091 3. Second package.json, specifically for electron app, is added. 4. main.js file with electron initalisation code is added.
Running Angular 1.3.13
base href to load all assets from a specific subdirectory
enable html 5 mode
Routes are setup like this:
Upon loading the application, the following error is thrown n times (I believe per anchor href on the page)
Debugging this issue, I found at this line:
$location.absUrl()
returnsundefined
My GUESS is that the base href is throwing off the matching of routes at $.when('/'), and so is undefined...
The text was updated successfully, but these errors were encountered: