Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

angular ngRoute breaks when using base tag #4442

Closed
jimmywarting opened this issue Oct 15, 2013 · 9 comments
Closed

angular ngRoute breaks when using base tag #4442

jimmywarting opened this issue Oct 15, 2013 · 9 comments

Comments

@jimmywarting
Copy link
Contributor

Demo:
http://plnkr.co/edit/TkADpfgchYVdvNTqRPFT?p=preview

Apparently it's because of the new changes to this: b019a48

It dose not complain when you are actually on that same url as the base href

@jimmywarting
Copy link
Contributor Author

looks like a duplicate of #3511 unsure

@eddiemonge
Copy link
Contributor

changing line https://github.com/angular/angular.js/blob/master/src/ng/location.js#L56 to:
if (whole && whole.indexOf(begin) == 0) {
produces what seems to be the real error:

Error: [$location:ipthprfx] Invalid url "undefined", missing path prefix "http://localhost:8000/0.0.2/".
http://errors.angularjs.org/1.2.0-dba566a/$location/ipthprfx?p0=undefined&p1=http%3A%2F%2Flocalhost%3A8000%2F0.0.2%2F
    at http://localhost:8000/js/angular.js:78:12
    at Object.LocationHtml5Url.$$parse (http://localhost:8000/js/angular.js:7629:13)
    at $LocationProvider.$get (http://localhost:8000/js/angular.js:8064:15)
    at Object.invoke (http://localhost:8000/js/angular.js:3374:28)
    at http://localhost:8000/js/angular.js:3213:37
    at getService (http://localhost:8000/js/angular.js:3331:39)
    at Object.invoke (http://localhost:8000/js/angular.js:3352:13)
    at http://localhost:8000/js/angular.js:3213:37
    at getService (http://localhost:8000/js/angular.js:3331:39)
    at Object.invoke (http://localhost:8000/js/angular.js:3352:13) 

@petebacondarwin
Copy link
Member

The problem is that $$rewrite is returning undefined. This should not happen.

@siddii
Copy link
Contributor

siddii commented Jan 2, 2014

This issue doesn't seem to exist in the latest build from master. Here is a plunkr showing that - http://plnkr.co/edit/LqWdroJBtM3O5iUiOVL7?p=preview

@jimmywarting
Copy link
Contributor Author

@siddii nope, the problem is still there, you just forgot the base tag updated the code to the latest version
http://plnkr.co/edit/TkADpfgchYVdvNTqRPFT?p=preview

@caitp
Copy link
Contributor

caitp commented Feb 5, 2014

There are two issues, one is probably very difficult to change at this point.

  1. the base tag sets the application's base url (and is therefore responsible for more than just how relative links are processed), this affects how urls get rewritten

  2. rewriting the base url which points to an external site means that you're going to be passing undefined to beginsWith() when $location is instantiated. This is the expected behaviour, as it's not expected that you'll set the base href to something external to the application.

We might need an alternative way to bootstrap the application, like a way to specify the "real" base url in a config block before $locationProvider.$get is ever called. I notice that PRs are welcome =)

caitp added a commit to caitp/angular.js that referenced this issue Feb 5, 2014
… path

In HTML, the <base> tag is used to configure how relative hyperlinks are resolved. In Angular, it
has another use, configuring how URLs are rewritten. Because of this, setting the base URL to some
external path outside of the application would cause $location.$$parse() to throw (which is the
desired behaviour).

This change enables developers to imperatively configure the application basePath, taking advantage
of the natural HTML use of the <base> tag without breaking Angular applications.

Example:

```
angular.module("test", [])
  .config(function($locationProvider) {
    $locationProvider.baseHref("http://foo.com/the/base/application/path/");
  });
```

Closes angular#4442
caitp added a commit to caitp/angular.js that referenced this issue Feb 5, 2014
… path

In HTML, the <base> tag is used to configure how relative hyperlinks are resolved. In Angular, it
has another use, configuring how URLs are rewritten. Because of this, setting the base URL to some
external path outside of the application would cause $location.$$parse() to throw (which is the
desired behaviour).

This change enables developers to imperatively configure the application basePath, taking advantage
of the natural HTML use of the <base> tag without breaking Angular applications.

Example:

```
angular.module("test", [])
  .config(function($locationProvider) {
    $locationProvider.baseHref("http://foo.com/the/base/application/path/");
  });
```

Closes angular#4442
@btford btford removed the gh: issue label Aug 20, 2014
@levarberry
Copy link

Using AJS 1.3.4 when HTML5mode is true ... AngularJS doesn't work at all.. Getting Error TypeError: Url is undefined.

@caitp
Copy link
Contributor

caitp commented Mar 18, 2015

@levarberry do you have a stack trace? please file a bug with more information, thanks!

@Narretz
Copy link
Contributor

Narretz commented Jun 7, 2016

Basically this is a request for the ngAppRoot directive: #3102

@Narretz Narretz closed this as completed Jun 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.