Skip to content

Instantly share code, notes, and snippets.

@foriequal0
Created April 30, 2024 04:58
Show Gist options
  • Save foriequal0/401979493579f488157a41d36cd28ed8 to your computer and use it in GitHub Desktop.
Save foriequal0/401979493579f488157a41d36cd28ed8 to your computer and use it in GitHub Desktop.
GitHub SPA listen navigation event
function onNavigate(listener) {
// GitHub uses Turbo for tab navigations.
// You can listen initial page load event, or subsequent tab navigations with this.
// https://turbo.hotwired.dev/reference/events#turbo%3Aload
window.addEventListener("turbo:load", listener);
// For the file/dir navigation, it emits following events to the document.
/*
export const SOFT_NAV_STATE = Object.freeze({
INITIAL: 'soft-nav:initial',
START: 'soft-nav:start',
SUCCESS: 'soft-nav:success',
ERROR: 'soft-nav:error',
FRAME_UPDATE: 'soft-nav:frame-update',
END: 'soft-nav:end',
RENDER: 'soft-nav:render',
PROGRESS_BAR: {
START: 'soft-nav:progress-bar:start',
END: 'soft-nav:progress-bar:end',
},
})
*/
document.addEventListener("soft-nav:end", listener);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment