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

html5Mode appbase regression in 1.1.5 #2799

Closed
clkao opened this issue May 26, 2013 · 20 comments
Closed

html5Mode appbase regression in 1.1.5 #2799

clkao opened this issue May 26, 2013 · 20 comments

Comments

@clkao
Copy link
Contributor

clkao commented May 26, 2013

I noticed that 58ef323 introduced html5Mode behaviour changes for determining appbase.

With html5Mode, given an app http://foo/, and a deep link url http://foo/bar/baz that can be reached with ng-href or something within the application, the appbase is /. However if the user goes to http://foo/bar/baz directly, the appbase becomes http://foo/bar, leaving the $$path to be /baz, and this breaks url router or ui-router.

@tomchentw
Copy link

Encounter same problem here. How can I fix this?
Say, my ng-app root at '/', but I still want 'foo/bar' to be deeply linked. But currently it can't.
Only path 'foo/:id' can be linked.

Is this behavior normal?

@jeme
Copy link

jeme commented May 26, 2013

Let me just see if I understand this correct...

If you go to: http://domain.com/ the app base is /... then you start browsing the page and goes to /path then on to /path/here/5 then if you hit refresh here, the app base is now /path/here ??

If that is the case, then this sounds like a severe error, and not just a behavior change... A changing App base is going to be horrible to work with? o.O...

@clkao
Copy link
Contributor Author

clkao commented May 26, 2013

@jeme yes that's right. I changed the summary to 'regression' which should now sound more severe than behaviour change ;)

@tomchentw
Copy link

@jeme Yes. But what do you mean that's a server error?

@jeme
Copy link

jeme commented May 26, 2013

@tomchentw Severe Error, Severe Bug, Severe Issue... And because that if you take my scenario, navigating to a "child" url inside an angular application or going directly to it though an external links leaves it in 2 different states, this is likely to break any existing angular app that uses HTML 5, not to mention how hard and illogical Html5 mode would behave...

I would expect the 2 scenarios where:

a. By Nav

  1. Open http://domain.com/ => base = '/', path= '/'
  2. Navigate to /path/here/5 => base = '/', path= '/path/here/5' (Url is now http://domain.com/path/here/5)

b. By Direct

  1. Open http://domain.com/path/here/5 => base = '?', path= '?'

I would expect B to be base = '/', path= '/path/here/5' where it sounds like its: base = '/path/here', path= '/5' which creates a complete different behavior.

Html 5 already present us with an option to define base path: http://www.w3schools.com/tags/tag_base.asp, alternatively let the $locationProvider have a setBasePath... Angular shouldn't try to infer this from the initial URL, as that will just cause trouble.

@tomchentw
Copy link

@jeme Your expect of B is what I think. Would this problem be solved if Angular can find appBaseUrl using base tag?
BTW, it's strange for me that http://domain.com/user/:id works but not http://domain.com/users/info.

@clkao
Copy link
Contributor Author

clkao commented May 26, 2013

adding <base href="/"> restores the original behaviour and makes ui-router work properly again.

This seems to be a saner default.

@chuckd
Copy link

chuckd commented May 29, 2013

@clkao that fix doesn't work for us - if I set the base href then all the relatives links break. Would work if we switched to absolute links though.

@frederic-bonjour
Copy link

Same problem for me: routing is broken after switching from 1.1.4 to 1.1.5 :(
I already have a <base href="..."/> which is not set to /, but to a different value (like http://server/path/), and 1.1.5 does not work.

Any suggestion to avoid this issue while keeping 1.1.5?
Thanks a lot!

@frederic-bonjour
Copy link

I found what breaks my routing process:
2c69a67#L1R530

I'm using jstree and it preventDefault() on links. In AngularJS 1.1.5, they now check if the event isDefaultPrevented...

I just have to find how to make them work together :)

@richardcrichardc
Copy link
Contributor

I can't see html5 mode working with page refreshes unless the app base is independent of the url the page was loaded on. Having the app base coming from the base tag doesn't work as it means relative links will not work.

To be clear by app base I mean the path that '/' is relative to in the router.

I would say app base should either default to '/' or have no default, you need to set the app base to activate HTML5 mode.

@wcandillon
Copy link

@richardcrichardc I agree.
With 1.1.5, I had to set my app base to '/' explicitly.

@michaelnatkin
Copy link

With 1.1.5, I had to set my app base to '/' explicitly.

@wcandillon How do you do that exactly? I'm just hitting this problem hard; my app has no deep linking, but my URLs are suddenly getting hosed with 1.1.5. Would like to try this solution. I can't use because it will screw up all my relative links.

@vendethiel
Copy link

<base href="/" />

@michaelnatkin
Copy link

Ah, ok, I thought that was what you meant.. but that will wreck any relative links we have on the page. I suppose I could make them all absolute. But it looks like another solution has been found here: #2833

@fessyfoo
Copy link

I think this is a duplicate of #2762 ? fixed in aef0980

@fessyfoo
Copy link

I second the suggestion from @jeme that $locationProvider have a method to set appBase so that it can be set without having to use the base[href] html tag.

The fix from @IgorMinar aef0980 simply removes the appBase guessing in html5 mode. it is either taken from base[href] or simply '/'

fessyfoo referenced this issue Jun 27, 2013
With the recent refactoring of $location service we changed this behavior
resulting in a regression.

Previously we thought that html5 mode always required base[href]
to be set in order for urls to resolve properly. It turns out that
base[href] is problematic because it makes anchor urls (#foo) to
always resolve to the base url, which is almost always incorrect
and results in all anchors links and other anchor urls (e.g. svg
references) to be broken.

For this reason, we should now start recommending that people just
deploy to root context (/) and not set the base[href] when using
the html5 mode (push/pop history state).

If it's impossible to deploy to the root context then either all
urls in the app must be absolute or base[href] must be set with the
caveat that anchor urls in such app won't work.

Closes #2762
@stenlylee
Copy link

#3145

@istarkov
Copy link

Here i make a fix, you can apply to your local angular
#3317

@IgorMinar
Copy link
Contributor

This was fixed by aef0980. There is another issue open for allowing the "approot" url to be configurable. Please see #3102

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