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

bug in $location path service in html5 mode #3317

Closed
istarkov opened this issue Jul 24, 2013 · 2 comments
Closed

bug in $location path service in html5 mode #3317

istarkov opened this issue Jul 24, 2013 · 2 comments

Comments

@istarkov
Copy link

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!!!

@istarkov
Copy link
Author

this fix also fix this issue #2799

@btford
Copy link
Contributor

btford commented Jan 10, 2014

Looks like aef0980 fixed this a while ago.

@btford btford closed this as completed Jan 10, 2014
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants