Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Last active November 9, 2019 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewstokeley/1bc60a61d1a2eafd532d4f858bcfc5bd to your computer and use it in GitHub Desktop.
Save matthewstokeley/1bc60a61d1a2eafd532d4f858bcfc5bd to your computer and use it in GitHub Desktop.
a barebones, hacky async route loader
// barebones and hacky asynchronous route loader
window.addEventListener('load', () => {
events.register('click', route);
const route = function(event) {
let module = event.target.dataset.module;
if (module === undefined) module = 'index'
return open(module);
}
const open = function(module) {
const req = new Request(config.path.root + config.path.modules + module)
return fetch(req).then((res) => { return res.text() }).then((text) => {
// appendToDomMethod (text)
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment