Skip to main content

Part 3 / Stores / updated

updated store は true または false を持ちます。これは最初にページを開いてからそれ以降にアプリの新バージョンがデプロイされたかどうかを表しています。これを動作させるには、svelte.config.jskit.version.pollInterval を指定する必要があります。

バージョンの変更はプロダクションでのみ発生し、開発時には発生しません。そのため、このチュートリアルでは $updated は常に false となります。

pollInterval とは関係なく、updated.check() を呼び出すと手動で新バージョンがデプロイされたかチェックできます。

src/routes/+layout.svelte
<script>
	import { page, navigating, updated } from '$app/stores';
</script>

<nav>
	<a href="/" aria-current={$page.url.pathname === '/'}>
		home
	</a>

	<a href="/about" aria-current={$page.url.pathname === '/about'}>
		about
	</a>

	{#if $navigating}
		navigating to {$navigating.to.url.pathname}
	{/if}
</nav>

<slot />

{#if $updated}
	<p class="toast">
		A new version of the app is available

		<button on:click={() => location.reload()}>
			reload the page
		</button>
	</p>
{/if}

Next: Errors and redirects

1
2
3
<h1>home</h1>
<p>this is the home page.</p>
 
initialising