The approach taken here is much simpler but less automatic. There are three elements that
differ between page two and page three: The heading, the link, and the main text at the
bottom. Theses are marked with data-swap="unique-name"
. Then this demo indeed use
the astro:before-swap
event to define a new implementation for swap()
that overwrites the marked elements in the current DOM with the corresponding elements from newDocument
and leaves everything else as it is.
Seen that the title of the browsers tab is still on page two? So we swapped those three marked
elements in, but we didn't yet swap the HTML <head>
with the title, yet :)