ngInclude causes redirect #2868
Description
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:
- Go to http://code.angularjs.org/1.1.5/docs/api/ng.directive:ngInclude
- Edit the example in Plnkr.
- Open example in new window.
- Append
index.html
to url.
Source of problem
This comes from the recent change to the URL interception behavior 58ef323 .
Refer to:
Lines 540 to 543 in 58ef323
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:
angular.js/test/ng/locationSpec.js
Lines 582 to 591 in 58ef323
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
.