友情链接: 精选头像网站

申请友情链接:前往contact us

网站访客量:1836


Image
Technology

The Svelte $lib directory is introduced into use🐛

Sometimes, code is used in multiple places. When this happens, it's useful to have a place to put them that can be accessed by all routes without needing to prefix imports with ../../../../. In SvelteKit, that place is the src/lib directory. Anything inside this directory can be accessed by any module in src via the $lib alias.

Both +page.svelte files in this exercise import src/lib/message.js. But if you navigate to /a/deeply/nested/route, the app breaks, because we got the prefix wrong. Update it to use $lib/message.js instead:

src/routes/a/deeply/nested/route/+page.svelte
<script>
	import { message } from '$lib/message.js';
</script>

<h1>a deeply nested route</h1>
<p>{message}</p>

Do the same for src/routes/+page.svelte:

src/routes/+page.svelte
<script>
	import { message } from '$lib/message.js';
</script>

<h1>home</h1>
<p>{message}</p>
Svelte Wednesday, September 18, 2024 11:41:01 AM

4
reviews
0
comments
by CF

Image
Technology

Svelte application status

Not all application state belongs to the application's component hierarchy. Sometimes, you need to have some values accessed by multiple unrelated components or regular JavaScript modules.
Svelte Saturday, September 14, 2024 3:01:09 PM

9
reviews
0
comments
by CF
Page

Designer: CFYYDS