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

ngInclude causes redirect  #2868

Closed
Closed
@chrisirhc

Description

@chrisirhc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions