This is part of the router in a single-page application I'm working on:
function navigateTo(url) {
return findOrCreatePageContainer(url) // finds div or creates new one
.then(loadAndInitPageIfNotAlreadyDone) // loads content into div
.catch(injectErrorMessage) // injects error message into div
.then(transitionToNewPage); // displays content in div