diff --git a/website/src/components/Playground/URLShortener.js b/website/src/components/Playground/URLShortener.js index 2e0194a1..4dc99190 100644 --- a/website/src/components/Playground/URLShortener.js +++ b/website/src/components/Playground/URLShortener.js @@ -28,11 +28,11 @@ export default class URLShortener extends Component<{}, State> { }; componentDidMount() { - window.addEventListener('hashchange', this.onHashChange); + window.addEventListener('popstate', this.onHashChange); } componentWillUnmount() { - window.removeEventListener('hashchange', this.onHashChange); + window.removeEventListener('popstate', this.onHashChange); } onHashChange = () => { diff --git a/website/src/components/Playground/index.js b/website/src/components/Playground/index.js index 327ca962..5a39f236 100644 --- a/website/src/components/Playground/index.js +++ b/website/src/components/Playground/index.js @@ -87,12 +87,18 @@ export default class Playground extends Component { document.addEventListener('keydown', this.onKeyDown); // rehydrate - if (window.location.hash && window.location.hash.length > 1) { + if (window.location.search && window.location.search.length > 1) { try { - const restoredState = JSON.parse(atob(window.location.hash.substr(1))); + const restoredState = JSON.parse( + atob(window.location.search.substr(1)), + ); this.setState({layoutDefinition: this.rehydrate(restoredState)}); } catch (e) { - window.location.hash = ''; + window.history.replaceState( + {}, + null, + window.location.origin + window.location.pathname, + ); } } } @@ -165,7 +171,14 @@ export default class Playground extends Component { }); if (this.props.persist) { - window.location.hash = this.getHash(layoutDefinition); + window.history.replaceState( + {}, + null, + window.location.origin + + window.location.pathname + + '?' + + this.getHash(layoutDefinition), + ); } }