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

Need to check "base" element in Html5 Hashbang mode #8172

Closed
winsontam opened this issue Jul 13, 2014 · 2 comments · Fixed by #8851
Closed

Need to check "base" element in Html5 Hashbang mode #8172

winsontam opened this issue Jul 13, 2014 · 2 comments · Fixed by #8851

Comments

@winsontam
Copy link
Contributor

In $rootElement onClick,

// relative path - join with current path
var stack = $location.path().split("/"),
parts = href.split("/");
for (var i=0; i<parts.length; i++) {
if (parts[i] == ".")
continue;
else if (parts[i] == "..")
stack.pop();
else if (parts[i].length)
stack.push(parts[i]);
}
absHref = appBase + prefix + stack.join('/');

This path should check is the "base" element set.
And don't join with current path if "base" element set.

@jeffbcross jeffbcross self-assigned this Jul 21, 2014
@jeffbcross jeffbcross added this to the Purgatory milestone Jul 21, 2014
@jeffbcross jeffbcross removed their assignment Jul 21, 2014
@jeffbcross
Copy link
Contributor

Can you provide a working use case showing this problem in plnkr

@winsontam
Copy link
Contributor Author

Hi,
Here is the sample code
http://plnkr.co/edit/mJdoeVo5Q2qiLJXyjR9O?p=preview

You can go by browser that don't support window.history.
When you click the link, it will append the previous path and cause the problem.
But it is no problem in browser that support window.history.

I think it need to check whether the element set.
If set, then don't append the previous path, just follow the element path is fine.

Please take a look at line 678
https://github.com/angular/angular.js/blob/master/src/ng/location.js

Thanks

@btford btford removed the gh: issue label Aug 20, 2014
tbosch added a commit to tbosch/angular.js that referenced this issue Aug 29, 2014
…` url

BREAKING CHANGE (since 1.2.0 and 1.3.0-beta.1):

Angular now requires a `<base>` tag when html5 mode of `$location` is enabled. Reasoning:
Using html5 mode without a `<base href="...">` tag makes relative links for images, links, ...
relative to the current url if the browser supports
the history API. However, if the browser does not support the history API Angular falls back to using the `#`,
and then all links would be broken.


BREAKING CHANGE (since 1.2.17 and 1.3.0-beta.10):

In html5 mode without a `<base>` tag on older browser that don't support the history API
relative paths were adding up. E.g. clicking on `<a href="page1">` and then on `<a href="page2">`
would produce `$location.path()==='/page1/page2'. The code that introduced this behavior was removed
and Angular now also requires a `<base>` tag to be present when using html5 mode.

Closes angular#8172
tbosch added a commit to tbosch/angular.js that referenced this issue Aug 29, 2014
…` url

BREAKING CHANGE (since 1.2.0 and 1.3.0-beta.1):

Angular now requires a `<base>` tag when html5 mode of `$location` is enabled. Reasoning:
Using html5 mode without a `<base href="...">` tag makes relative links for images, links, ...
relative to the current url if the browser supports
the history API. However, if the browser does not support the history API Angular falls back to using the `#`,
and then all links would be broken.

BREAKING CHANGE (since 1.2.17 and 1.3.0-beta.10):

In html5 mode without a `<base>` tag on older browser that don't support the history API
relative paths were adding up. E.g. clicking on `<a href="page1">` and then on `<a href="page2">`
would produce `$location.path()==='/page1/page2'. The code that introduced this behavior was removed
and Angular now also requires a `<base>` tag to be present when using html5 mode.

Closes angular#8172
tbosch added a commit to tbosch/angular.js that referenced this issue Aug 29, 2014
…` url

BREAKING CHANGE (since 1.2.0 and 1.3.0-beta.1):

Angular now requires a `<base>` tag when html5 mode of `$location` is enabled. Reasoning:
Using html5 mode without a `<base href="...">` tag makes relative links for images, links, ...
relative to the current url if the browser supports
the history API. However, if the browser does not support the history API Angular falls back to using the `#`,
and then all those relative links would be broken.

The `<base>` tag is also needed when a deep url is loaded from the server, e.g. `http://server/some/page/url`.
In that case, Angular needs to decide which part of the url is the base of the application, and which part
is path inside of the application.

To summarize: Now all relative links are always relative to the `<base>` tag.

Exception (also a breaking change):
Link tags whose `href` attribute starts with a `#` will only change the hash of the url, but nothing else
(e.g. `<a href="#someAnchor">`). This is to make it easy to scroll to anchors inside a document.

Related to angular#6162
Closes angular#8492

BREAKING CHANGE (since 1.2.17 and 1.3.0-beta.10):

In html5 mode without a `<base>` tag on older browser that don't support the history API
relative paths were adding up. E.g. clicking on `<a href="page1">` and then on `<a href="page2">`
would produce `$location.path()==='/page1/page2'. The code that introduced this behavior was removed
and Angular now also requires a `<base>` tag to be present when using html5 mode.

Closes angular#8172, angular#8233
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants