examples/svelte/star-wars-sveltekit
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Svelte Query Star Wars Example (SvelteKit)#
A multi-page Star Wars app with films and characters, where each page fetches its own data.
Built with SvelteKit.
How it works#
src/lib/services/characters/queries.ts,src/lib/services/films/queries.tsandsrc/lib/services/planets/queries.tsdefinelist()anddetail(id)factories withqueryOptions, keyed by['characters', ...],['films', ...]and['planets', ...]. The matchingapi.tsfiles fetch from SWAPI.src/routes/+layout.sveltecreates theQueryClientwithenabled: browser, so queries only run in the browser.- Each SvelteKit page reads its own data with
createQuery:src/routes/characters/+page.svelteandsrc/routes/films/+page.svelteread the lists,src/routes/characters/[characterId]/+page.svelteandsrc/routes/films/[filmId]/+page.svelteread a detail. - The detail pages render
src/routes/characters/[characterId]/Film.svelte,src/routes/characters/[characterId]/Homeworld.svelteandsrc/routes/films/[filmId]/Character.svelte, each with its owncreateQueryper related id. Details you have already opened come from the cache when you navigate back.
To run this example:
npm installnpm run dev