Merge pull request from benjiwheeler/hash-redirect

redirect hash urls to url pathnames
This commit is contained in:
Benjamin Wheeler 2018-11-20 16:06:46 -05:00 committed by GitHub
commit 95fb947c08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -778,6 +778,23 @@ const ConnectedPreview = connect(
mapDispatchToProps
)(Preview);
// replace old Scratch 2.0-style hashtag URLs with updated format
if (window.location.hash) {
let pathname = window.location.pathname;
if (pathname.substr(-1) !== '/') {
pathname = `${pathname}/`;
}
if (window.location.hash === '#editor') {
history.replaceState({}, document.title,
`${pathname}editor${window.location.search}`);
}
if (window.location.hash === '#fullscreen') {
history.replaceState({}, document.title,
`${pathname}fullscreen${window.location.search}`);
}
}
// initialize GUI by calling its reducer functions depending on URL
GUI.setAppElement(document.getElementById('app'));
const initGuiState = guiInitialState => {
const pathname = window.location.pathname.toLowerCase();