Skip to content

Commit 8ee81dc

Browse files
author
Rich Harris
committed
reload docs
1 parent d8b1832 commit 8ee81dc

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Reloading the page
3+
---
4+
5+
Ordinarily, SvelteKit will navigate between pages without refreshing the page. In this exercise, if we navigate between `/` and `/about`, the timer keeps on ticking.
6+
7+
In rare cases, you might want to disable this behaviour. You can do so by adding the `data-sveltekit-reload` attribute on an individual link, or any element that contains links:
8+
9+
```svelte
10+
/// file: src/routes/+layout.svelte
11+
<nav +++data-sveltekit-reload+++>
12+
<a href="/">home</a>
13+
<a href="/about">about</a>
14+
</nav>
15+
```
16+
17+
For more information on available link options and their values, consult the [link options documentation](https://kit.svelte.dev/docs/link-options).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script>
2+
import { onMount } from 'svelte';
3+
4+
let seconds = 0;
5+
6+
onMount(() => {
7+
const interval = setInterval(() => {
8+
seconds += 1;
9+
}, 1000);
10+
11+
return () => {
12+
clearInterval(interval);
13+
};
14+
});
15+
</script>
16+
17+
<nav>
18+
<a href="/">home</a>
19+
<a href="/about">about</a>
20+
</nav>
21+
22+
<slot />
23+
24+
<p>the page has been open for {seconds} seconds</p>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>home</h1>
2+
<p>this is the home page.</p>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>about</h1>
2+
<p>this is the about page.</p>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script>
2+
import { onMount } from 'svelte';
3+
4+
let seconds = 0;
5+
6+
onMount(() => {
7+
const interval = setInterval(() => {
8+
seconds += 1;
9+
}, 1000);
10+
11+
return () => {
12+
clearInterval(interval);
13+
};
14+
});
15+
</script>
16+
17+
<nav data-sveltekit-reload>
18+
<a href="/">home</a>
19+
<a href="/about">about</a>
20+
</nav>
21+
22+
<slot />
23+
24+
<p>the page has been open for {seconds} seconds</p>

0 commit comments

Comments
 (0)