This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat($location): test $location enhancements from #6421 and fix them #6899
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,6 +268,16 @@ function LocationHashbangInHtml5Url(appBase, hashPrefix) { | |
return appBaseNoFile; | ||
} | ||
}; | ||
|
||
this.$$compose = function() { | ||
var search = toKeyValue(this.$$search), | ||
hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; | ||
|
||
this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; | ||
// include hashPrefix in $$absUrl when $$url is empty so IE8 & 9 do not reload page because of removal of '#' | ||
this.$$absUrl = appBase + hashPrefix + this.$$url; | ||
}; | ||
|
||
} | ||
|
||
|
||
|
@@ -642,6 +652,39 @@ function $LocationProvider(){ | |
absHref = urlResolve(absHref.animVal).href; | ||
} | ||
|
||
// Make relative links work in HTML5 mode for legacy browsers (or at least IE8 & 9) | ||
// The href should be a regular url e.g. /link/somewhere or link/somewhere or ../somewhere or | ||
// somewhere#anchor or http://example.com/somewhere | ||
if (LocationMode === LocationHashbangInHtml5Url) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like it would make sense to have a "preprocessing" method in LocationMode, so that this code could be removed from here, and more easily extended for the other location modes. I guess it's sort of like a special version of $$rewrite that wants the relative url rather than the absolute |
||
// get the actual href attribute - see | ||
// http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx | ||
var href = elm.attr('href') || elm.attr('xlink:href'); | ||
|
||
if (href.indexOf('://') < 0) { // Ignore absolute URLs | ||
var prefix = '#' + hashPrefix; | ||
if (href[0] == '/') { | ||
// absolute path - replace old path | ||
absHref = appBase + prefix + href; | ||
} else if (href[0] == '#') { | ||
// local anchor | ||
absHref = appBase + prefix + ($location.path() || '/') + href; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe |
||
} else { | ||
// 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('/'); | ||
} | ||
} | ||
} | ||
|
||
var rewrittenUrl = $location.$$rewrite(absHref); | ||
|
||
if (absHref && !elm.attr('target') && rewrittenUrl && !event.isDefaultPrevented()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do we cause the page reload here? when an app uses routing, the path is always set, so this override shouldn't change anything.
if the path is not set then we should investigate why.
the original thinking was that we don't want to append '#' in hashbang mode unless you actually use $location, otherwise you end up with apps that change the url needlessly, which is something we wanted to avoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line was added by the original PR, so I think we have to ask them. I don't have access to IE9 to debug that easily except on SL, so it's hard for me to say.