-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow replaceState via
Location.replaceState
#4
- Loading branch information
Showing
2 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,21 @@ var onClickHandler = function (e) { | |
throw err; | ||
} | ||
}; | ||
|
||
var replaceState = function(historyState) { | ||
// XXX: should we throw / warn / do nothing here? | ||
if (isUsingHashPaths()) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tmeasday
Author
Contributor
|
||
throw new Error("Can't replaceState when using hash paths"); | ||
|
||
var state = current; | ||
if (EJSON.equals(state.options.historyState, historyState)) | ||
return; | ||
|
||
state.options.historyState = historyState; | ||
history.replaceState(historyState, null, state.url); | ||
dep.changed(); | ||
} | ||
|
||
/*****************************************************************************/ | ||
/* Location API */ | ||
/*****************************************************************************/ | ||
|
@@ -228,6 +243,13 @@ Location.go = function (url, options) { | |
return go(url, options); | ||
}; | ||
|
||
/** | ||
* Update the history.state for the given location | ||
*/ | ||
Location.replaceState = function(historyState) { | ||
return replaceState(historyState); | ||
} | ||
|
||
/** | ||
* Automatically start Iron.Location | ||
*/ | ||
|
Definitely shouldn't throw an error here.
If you call
history.replaceState
does it fire thepopstate
event? Otherwise, I think you should also be setting or updating the state object you get from calling Location.get(). So the idea of usinghistory
is sort of optional, but what you get from calling theget()
method is always consistent.