bug in $location path service in html5 mode #3317
Description
On full page reload in browser (ctrl f5)
$location.path() will be equal to word after last forward slash for any app url.
example
url: http://localhost:3000/some/word
$location.path() after reload will be equal to "word"
this bug affects that $routeProvider can't work for routes like
$routeProvider.when('/:id_1/:id_2', {...}) after page reload
Where is no need in reproduce this bug, because of simple source:
file:
https://github.com/angular/angular.js/blob/master/src/ng/location.js
method:
stripFile called from LocationHtml5Url get url like http://aaa/bbb/ccc and returns
this part http://aaa/bbb/ but must return http://aaa/
(this code work on local html5 locations because of, if first url is equal to
http://aaa/ the method stripFile returns http://aaa/ and cach result in var appBaseNoFile, so next calls to this.$$parse use normal appBaseNoFile for calculations)
fix:
add method
function stripHTML5File(url) {
var url_repl = url.replace('//','-$%^%$-'); //-$%^%$- need be replaced with some UID
return url_repl.substr(0, stripHash(url_repl).indexOf('/') + 1).replace('-$%^%$-', '//');;
}
replace var appBaseNoFile = stripFile(appBase); call from LocationHtml5Url to
var appBaseNoFile = stripHTML5File(appBase);
so LocationHtml5Url will be
function stripHTML5File(url) {
var url_repl = url.replace('//','-$%^%$-');
return url_repl.substr(0, stripHash(url_repl).indexOf('/') + 1).replace('-$%^%$-', '//');;
}
function LocationHtml5Url(appBase, basePrefix) {
basePrefix = basePrefix || '';
var appBaseNoFile = stripHTML5File(appBase);
Thank you guys for really cool application and really clean source code!!!
Activity
istarkov commentedon Jul 24, 2013
this fix also fix this issue #2799
btford commentedon Jan 10, 2014
Looks like aef0980 fixed this a while ago.