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

ngInclude causes redirect #2868

Closed
chrisirhc opened this issue Jun 3, 2013 · 4 comments
Closed

ngInclude causes redirect #2868

chrisirhc opened this issue Jun 3, 2013 · 4 comments

Comments

@chrisirhc
Copy link
Contributor

As of 1.1.5, using ngInclude on a page that has a path that does not end with a hash or a slash and without configuring the $routeProvide.html5Mode causes a redirect.

For example:
http://server/base -> http://server/base#/base

Here is a live example:

Open the live preview and append index.html in http://plnkr.co/edit/5uW6HBun5AAwMJ7QYUq4
Or, if it works: http://run.plnkr.co/BRvHmL7ookHPdxAN/index.html

Steps to reproduce:

  1. Go to http://code.angularjs.org/1.1.5/docs/api/ng.directive:ngInclude
  2. Edit the example in Plnkr.
  3. Open example in new window.
  4. Append index.html to url.

Source of problem

This comes from the recent change to the URL interception behavior 58ef323 .

Refer to:

// rewrite hashbang url <> html5 url
if ($location.absUrl() != initialUrl) {
$browser.url($location.absUrl(), true);
}

This seems to be by design since in the spec mentions that html5 history should correctly convert html5 url with path matching basepath to hashbang url:

it('should correctly convert html5 url with path matching basepath to hashbang url', function () {
initService(true, '!', false);
inject(
initBrowser('http://domain.com/base/index.html', '/base/index.html'),
function($browser, $location) {
expect($browser.url()).toBe('http://domain.com/base/index.html#!/index.html');
}
);
});
});

I suggest that this behavior should be opt-in since I don't think generally people would be expecting to be using the $location whenever ngInclude is used. Even the use of $route just for the autoscroll functionality seems a little overkill. Perhaps provide a way to disable $location (or just its redirects) or make the setup explicit (perhaps requiring the user to include $location as an explicit dependency on their module configuration.

A user might expect a redirect when using $route but not when using $location. It seems a little unusual that $location would simply cause a redirect through $locationProvider.$get.

@XtraKrispi
Copy link

I second this. We are having issues with our routes because it's duplicating the last portion of the url in the hash.

@barakka
Copy link

barakka commented Jul 16, 2013

I also vote for this, as I'm seeing this problem. Just by adding ng-include to the page the browser location is changed and the hash is included, even if I'm not using $route or $location. So a way to disable this behavior would be appreciated.

@chrisirhc
Copy link
Contributor Author

More discussion at #2860 .

@chrisirhc
Copy link
Contributor Author

Fixed in d4d34ab

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants