Skip to content

Commit 6e649ce

Browse files
committed
Fix showing page content on back button navigation
1 parent 70dd08f commit 6e649ce

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/layouts/Layout.astro

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ const currentPath = Astro.url.pathname;
4545
</div>
4646

4747
<script>
48-
document.addEventListener('DOMContentLoaded', () => {
48+
const initPage = () => {
4949
document.body.style.opacity = '0';
5050
document.body.style.transition = 'opacity 150ms ease-out';
5151

5252
requestAnimationFrame(() => {
5353
document.body.style.opacity = '1';
5454
});
55+
};
56+
57+
document.addEventListener('DOMContentLoaded', () => {
58+
initPage();
5559

5660
const links = document.querySelectorAll('a[href^="/"], a[href^="./"], a[href^="../"]');
5761

@@ -77,6 +81,12 @@ const currentPath = Astro.url.pathname;
7781
});
7882
});
7983
});
84+
85+
window.addEventListener('pageshow', (event) => {
86+
if (event.persisted) {
87+
initPage();
88+
}
89+
});
8090
</script>
8191
</body>
8292
</html>

0 commit comments

Comments
 (0)