Vai al contenuto principale
ProdottiStrumenti desktopTASTECADVisualizzazione disegniTASTEFILESGestione fileTASTEFTPTrasferimento fileTASTESSHSpazio di lavoro remotoTASTEZIPCompressione ed estrazioneTASTEWINMGestione fileStrumenti per sviluppatoriTASTECODEAmbiente di sviluppo integrato per RustTASTESTUDIOAmbiente integrato di sviluppo e testTASTEETLIntegrazione dati (ETL)ServerTASTEREMOTEServer di desktop remotoTASTEGEOServer geospazialeTASTEMAILSpazio di lavoro emailInvestimentiTASTESTOCKApp desktop di trading automatico azionarioIniziaDownloadDocumentazioneAcquistaTutti i prodotti
Marketplace
Notizie
TecnologiaNotizieNotizie di sviluppo di oggiDocumentazioneLinguaggi di programmazioneRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFramework frontend webNext.jsReactVue.js · NuxtSvelteKitAngularFramework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFramework per app e desktopTauriFlutterReact NativeElectronAlgoritmiBasi degli algoritmiAlgoritmi fondamentaliAlgoritmi avanzatiAlgoritmi pratici
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrinaGuida alla community
CollaboraTrasferimento tecnicoRealizzazione del sito webRealizzazione di app desktopPipeline di rilascio e pagamentoPartner commercialeContatti
ServiziDesktop remotoPacchetti di installazione su misura
TASTEDEV
Prodotti

Strumenti desktop

TASTECADApri con leggerezza anche i disegni più complessiTASTEFILESSolo i file che servono, alla massima velocitàTASTEFTPLa via più ordinata per i tuoi fileTASTESSHUn legame più solido tra te e i tuoi serverTASTEZIPComprimi più veloce, estrai più sicuroTASTEWINMUn file manager a due pannelli pensato per la tastiera

Strumenti per sviluppatori

TASTECODEModifica, compila, esegui il debug e testa app Rust in un'unica finestraTASTESTUDIODalla modifica ai test remoti e alle correzioni IA approvateTASTEETLSposta i dati guardando i valori

Server

TASTEREMOTEUn desktop remoto che gira sul tuo serverTASTEGEOUn server geospaziale compatibile con GeoServer, ricostruito in RustTASTEMAILRiprendi il controllo della tua posta

Investimenti

TASTESTOCKTrading automatico azionario secondo le regole che decidi tu: quando e che cosa

Inizia

DownloadUltime versioni di ogni prodottoDocsCome usare ogni prodottoAcquistaAbbonamenti e licenze perpetueTutti i prodottiTutti i prodotti a colpo d’occhio
Tutti i prodotti
MarketplaceNotizie
Tecnologia

Notizie

Notizie di sviluppo di oggiAnnunci ufficiali su linguaggi, framework, GitHub e IADocumentazioneGuide a linguaggi, framework e algoritmi

Linguaggi di programmazione

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Framework

Framework frontend webNext.jsReactVue.js · NuxtSvelteKitAngular
Framework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Framework per app e desktopTauriFlutterReact NativeElectron

Algoritmi

Basi degli algoritmiAnalisi della complessità · Ordinamento · Ricerca · Strutture dati di base · Alberi e heapAlgoritmi fondamentaliVisita dei grafi · Cammini minimi e alberi ricoprenti · Programmazione dinamica · Algoritmi greedy · Divide et impera · BacktrackingAlgoritmi avanzatiAlgoritmi sulle stringhe · Matematica e teoria dei numeri · Manipolazione dei bit · Alberi di segmenti · Union-FindAlgoritmi praticiStrategia per colloqui di programmazione · Cache LRU · Rate limiting · Hashing consistente
Tutta la documentazione di sviluppo
Community
ProgettiScopri sviluppatori e lavoriLog di sviluppoDecisioni e lezioni appresePromptIstruzioni riutilizzabiliProblemi degli strumenti di IAProblemi e alternative di Claude, Codex, GeminiVetrinaRisultati completatiGuida alla communityCome sviluppiamo in modo aperto
Collabora
Trasferimento tecnicoApp native in Rust ed eguiRealizzazione del sito web10 lingue, account, documentazione e downloadRealizzazione di app desktopRust ed egui, senza WebViewPipeline di rilascio e pagamentoFirma, MSI, deb, rpm, AppImage, hashPartner commercialeConsigliaci e ricevi il 30%ContattiSviluppo, partnership e investimenti
Servizi
Desktop remotoRaggiungi il tuo computer dal browserPacchetti di installazione su misuraSolo il necessario, impostazioni precaricate
Acquista
IT
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Accedi
Accedi
TASTEDEV

Dai piccoli strumenti a uno sviluppo migliore.

support@tastedev.netSostieni TASTEDEV
ProdottiGamma di prodottiAcquistaDocsDownloadMarketplaceAssistenza
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrina
NormeChi siamoInformativa sulla privacyTermini di servizioCondizioni di abbonamentoRimborsiLinee guida della community
AccountAccediRegistrati
Visitatori
Oggi
Ieri
Visualizzazioni totali
Società
GXSOFT
Rappresentante
CHOI YOUNG GU
Numero di registrazione
853-44-00368
Indirizzo
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefono
+82-10-4404-1523
E-mail
whitecalvin@tastedev.net
Responsabile privacy
CHOI YOUNG GU

© 2026 TASTEDEVLe informazioni sui prodotti si basano su fonti di sviluppo verificate.Rilasciato · in miglioramento

Documentazione di SvelteKit
SvelteKit
Getting Started with SvelteKitProject StructureCore ConceptsData and StateTestingBuilding and Deployment
Discussioni

Guida a SvelteKit · 4/6

Data and State

Per ora questo capitolo è disponibile solo in inglese.

In SvelteKit you read page data with load functions and change data with form actions. This chapter covers both, along with API endpoints, server-only modules, environment variables and state shared between components.

Two kinds of load functions

A load in +page.ts is a universal load: it runs on the server for the first request and in the browser for later client-side navigations. A load in +page.server.ts is a server load: it always runs on the server, so it can talk to a database or use secret keys. Either way, the object it returns becomes the page's data prop.

// src/routes/blog/[slug]/+page.server.ts
import { error } from '@sveltejs/kit';
import { db } from '#lib/server/db.js';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ params }) => {
  const post = await db.post.findBySlug(params.slug);
  if (!post) error(404, 'Post not found');

  return { post };
};
<!-- src/routes/blog/[slug]/+page.svelte -->
<script lang="ts">
  import type { PageProps } from './$types';
  let { data }: PageProps = $props();
</script>

<h1>{data.post.title}</h1>
<p>{data.post.summary}</p>

./$types is generated by SvelteKit for each route, so params.slug and data.post are typed automatically. Calling error() or redirect() stops execution immediately, so there is no need to throw them. In a universal load, use the fetch passed in as an argument: during SSR it handles cookies and relative URLs correctly, and its responses are inlined into the HTML so the browser does not repeat the request. Data returned from a layout's load is merged into the data of child pages, and child loads can read it with await parent().

API endpoints

A +server.ts file exports functions named after HTTP methods. Each receives a standard Request and returns a Response; use the standard Response.json() for JSON.

// src/routes/api/search/+server.ts
import type { RequestHandler } from './$types';
import { searchPosts } from '#lib/server/search.js';

export const GET: RequestHandler = async ({ url }) => {
  const q = url.searchParams.get('q') ?? '';
  const results = await searchPosts(q);
  return Response.json({ q, results });
};

Form actions

Mutations belong in the actions export of +page.server.ts. They work with a plain <form method="POST">, so they function without JavaScript, and adding use:enhance updates the page in place without a full reload. When validation fails, return with a status code and data for the form.

Domande su questo capitolo?
Capitolo precedenteCore ConceptsCapitolo successivoTesting
fail()
// src/routes/subscribe/+page.server.ts
import { fail, redirect } from '@sveltejs/kit';
import { db } from '#lib/server/db.js';
import type { Actions } from './$types';

export const actions = {
  default: async ({ request }) => {
    const form = await request.formData();
    const email = String(form.get('email') ?? '');

    if (!email.includes('@')) {
      return fail(400, { email, invalid: true });
    }

    await db.subscriber.create({ email });
    redirect(303, '/subscribe/thanks');
  }
} satisfies Actions;
<script lang="ts">
  import { enhance } from '$app/forms';
  import type { PageProps } from './$types';
  let { form }: PageProps = $props();
</script>

<form method="POST" use:enhance>
  <input name="email" type="email" value={form?.email ?? ''} />
  {#if form?.invalid}<p class="error">Please check your email address.</p>{/if}
  <button>Subscribe</button>
</form>

With several actions, give each a name in actions and target it with action="?/register".

Server-only modules and environment variables

A module with a server segment in its file name (db.server.ts) or inside a server folder (src/lib/server/) cannot be imported by browser code; if it is, the build fails with an error. Environment variables are declared in src/env.ts and imported from $app/env/private or $app/env/public. Variables are private by default; only those marked public: true are available in the browser.

// src/env.ts
import { defineEnvVars } from '@sveltejs/kit/env';

export const variables = defineEnvVars({
  DATABASE_URL: {},
  SITE_NAME: { public: true }
});

// then, in src/lib/server/db.ts:
// import { DATABASE_URL } from '$app/env/private';

The $env/* modules you may see in older material, such as $env/static/private, are deprecated in the current release. For per-request values like the signed-in user, set them on event.locals in the handle hook of src/hooks.server.ts and read them in server loads and actions.

Shared state

When several components need the same state, put $state in a .svelte.ts file and export it. Runes are allowed in files with that extension.

// src/lib/cart.svelte.ts
export const cart = $state({ items: [] as { id: string; qty: number }[] });

export function addToCart(id: string) {
  const found = cart.items.find((item) => item.id === id);
  if (found) found.qty += 1;
  else cart.items.push({ id, qty: 1 });
}

Be careful on the server, though: it is a single long-lived process shared by every user, so per-user data stored in module-level state can leak between requests. Pass per-user data down from load through data, or attach it to the component tree with Svelte's setContext and getContext, which are created fresh for each request. State that should survive a reload, such as filters or sort order, fits well in URL search params like ?sort=price. Stores from svelte/store, such as writable, still work, but runes are the default for new code.

Summary

  • Load page data with load in +page.ts (universal) or +page.server.ts (server).
  • Handle mutations with form actions and use:enhance; build external APIs with +server.ts.
  • Keep secrets on the server with server modules and $app/env/private.
  • Share state through $state in .svelte.ts files, but never keep per-user data in server module state.

0 commenti

Commenti principaliPrima i più recenti

Accedi · Accedi per lasciare un commento.