Skip to content

Commit

Permalink
Merge pull request #28 from swup/feat/astro-events
Browse files Browse the repository at this point in the history
Trigger custom events to simulate Astro lifecycle
  • Loading branch information
daun authored Nov 17, 2024
2 parents 9c5f8fb + 6143476 commit acedc8f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ export function buildInitScript(options: Partial<Options> = {}): string {
]
});
const dispatch = (name) => document.dispatchEvent(new Event(name));
// Trigger custom events to simulate Astro load lifecycle
swup.hooks.before('content:replace', () => dispatch('astro:before-swap'));
swup.hooks.on('content:replace', () => dispatch('astro:after-swap'));
swup.hooks.on('page:view', () => dispatch('astro:page-load'));
${globalInstance ? 'window.swup = swup;' : ''}
}
Expand Down

0 comments on commit acedc8f

Please sign in to comment.