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

Share a rebus (via this.props.current) #170

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/js/components/rebus.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export function Rebus(props, ...children) {
this.$element.querySelector('input').focus();
},
componentDidUpdate() {
const rebus = this.props.rebuses[this.props.current];
/* If history API isn't available, we shouldn't revert to the more widely available `window.location.href`,
as it incurs a new HTTP request and thus results in an infinite loop (and breaks SPAs). */
if (window.history) {
window.history.pushState('', '', `/?rebus=${rebus.id}`);
}
this.$element.querySelector('input').focus();
},
render({ current, rebuses, animation }) {
Expand Down