Fixed url state copy/paste bug

This commit is contained in:
jpellizzari
2017-03-16 15:02:06 -07:00
parent 3ade2933eb
commit 5da40d24c3

View File

@@ -90,20 +90,21 @@ export function updateRoute(getState) {
export function getRouter(dispatch, initialState) {
let mergedState = initialState;
// strip any trailing '/'s.
page.base(window.location.pathname.replace(/\/$/, ''));
const storageState = storageGet(STORAGE_STATE_KEY);
if (storageState) {
window.location.hash = `!/state/${storageState}`;
const parsedState = JSON.parse(decodeURL(storageState));
mergedState = { ...initialState, ...parsedState };
}
page('/', () => {
// recover from storage state on empty URL
dispatch(route(mergedState));
const storageState = storageGet(STORAGE_STATE_KEY);
if (storageState) {
// push storage state to URL
window.location.hash = `!/state/${storageState}`;
const parsedState = JSON.parse(decodeURL(storageState));
const mergedState = Object.assign(initialState, parsedState);
dispatch(route(mergedState));
} else {
dispatch(route(initialState));
}
});
page('/state/:state', (ctx) => {