You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If setHash is called, and the resulting changed signal calls replaceHash, then replaceHash replaces the previous history entry instead of the new history entry.
For example: Hash fragment is /, and setHash('/a') is called. Crossroads.js is used to redirect '/a' to '/a/b' (by calling replaceHash). The history after doing this should be '/', '/a/b', but instead, '/' is replaced with '/a/b', so the history is '/a/b', '/a/b'.
It looks like this is caused by setHash and replaceHash updating window.location after calling _registerChange. (setHash's _registerChange triggers replaceHash, and replaceHash replaces window.location before setHash can update window.location.) If they instead updated window.location first, then that would fix this issue (but may raise other issues; I'm not familiar enough with the code and with browser implementations to know).
For now, I'm using this function as a workaround.
function setHashWithPossibleRedirect(hash)
{
var old_hash = window.location.hash.replace(/^#/, '');
hasher.changed.active = false;
hasher.setHash(hash);
hasher.changed.active = true;
hasher.changed.dispatch(hash, old_hash);
}
The text was updated successfully, but these errors were encountered:
Yes, the changed signal is triggered before the browser updates the window.location.hash. The browser hashchange event takes a while to be dispatched so consecutive calls to setHash and getHash would return different values. I decided to normalize the behavior to make sure that getHash would always return the last value passed to setHash.
This is the kind of change that would require a v2.0 release - breaking change and conceptually different.
I will keep this issue open for now since it might be a good idea to change the whole behavior and do a 2.0 release in the future.
If setHash is called, and the resulting changed signal calls replaceHash, then replaceHash replaces the previous history entry instead of the new history entry.
For example: Hash fragment is /, and setHash('/a') is called. Crossroads.js is used to redirect '/a' to '/a/b' (by calling replaceHash). The history after doing this should be '/', '/a/b', but instead, '/' is replaced with '/a/b', so the history is '/a/b', '/a/b'.
It looks like this is caused by setHash and replaceHash updating window.location after calling _registerChange. (setHash's _registerChange triggers replaceHash, and replaceHash replaces window.location before setHash can update window.location.) If they instead updated window.location first, then that would fix this issue (but may raise other issues; I'm not familiar enough with the code and with browser implementations to know).
For now, I'm using this function as a workaround.
The text was updated successfully, but these errors were encountered: