Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

replaceHash with BASE url is replacing the entire path #64

Open
lsmag opened this issue Aug 12, 2014 · 2 comments
Open

replaceHash with BASE url is replacing the entire path #64

lsmag opened this issue Aug 12, 2014 · 2 comments

Comments

@lsmag
Copy link

lsmag commented Aug 12, 2014

Hello,

I'm using hasher in a page that contains a certain base url while the app itself is served in /myapp/, like:

<base href="http://my.domain/">

I did it so to do xhr requests without any special code, xhr.get('my/url') calls http://my.domain/my/url, as expected.

Problem is, I'm using replaceHash to put the url in an initial state, but it's not working well, because it's replacing the entire path:

// url is "http://my.domain/myapp/"

// If I use
hasher.setHash('users')
// url now is "http://my.domain/myapp/#/users"

// But, using replaceHash
hasher.replaceHash('users')
// url now is "http://my.domain/#/users"

Isn't it odd? ReplaceHash and setHash should work similarly, or shouldn't they?

@sb-relaxt-at
Copy link

That's a nasty bug. The following patch to replaceHash seems to solve this:

var currentLocationWithoutHash = location.protocol+'//'+location.hostname+(location.port?":"+location.port:"")+location.pathname+(location.search?location.search:"");
window.location.replace(currentLocationWithoutHash + '#' + path);

@klzns
Copy link

klzns commented Jul 2, 2019

I created a fork with @sb-relaxt-at's suggestion here:
https://github.com/vtex/Hasher

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants