by laktek · 9y ago · 0 comments
Only part you might have to spend some time to figure out would be compiling and module bundling. I suggest picking Webpack2 [2] and going through its guides to get up to speed with it.
Avoid frameworks and UI libraries like React and Vue until you really have a good grasp of the eco-system and problem you are trying to solve.
[0] https://developer.mozilla.org/en/docs/Web/API/CustomEvent
[1] https://developer.mozilla.org/en-US/docs/Web/API/History_API...
Can you please expand on this?
For now, I will share this snippet:
document.addEventListener('state-change', (ev) => {
const { key, action } = ev.detail;
const state = { key, action };
window.history.pushState(state, null, `/${action}/${key}`);
console.log(`triggered state change. action: ${action} key: ${key}`);
return handleState(state);
});
And then in your app code (for example, when a user clicks a button), trigger a state change: const event = new CustomEvent('state-change', {
detail : {
state: state,
key: key
}
});
document.dispatchEvent(event);