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

bug in $location path service in html5 mode #3317

Closed
@istarkov

Description

@istarkov

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

istarkov commented on Jul 24, 2013

@istarkov
Author

this fix also fix this issue #2799

btford

btford commented on Jan 10, 2014

@btford
Contributor

Looks like aef0980 fixed this a while ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @btford@istarkov

        Issue actions

          bug in $location path service in html5 mode · Issue #3317 · angular/angular.js