examples/svelte/rick-morty-sveltekit
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Svelte Query Rick And Morty Example (SvelteKit)#
A multi-page Rick and Morty app with characters and episodes, where each page fetches its own data.
Built with SvelteKit.
How it works#
src/lib/services/characters/queries.ts,src/lib/services/episodes/queries.tsandsrc/lib/services/locations/queries.tsdefinelist()anddetail(id)factories withqueryOptions, keyed by['characters', ...],['episodes', ...]and['locations', ...]. The matchingapi.tsfiles fetch from the Rick and Morty API.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/episodes/+page.svelteread the lists,src/routes/characters/[characterId]/+page.svelteandsrc/routes/episodes/[episodeId]/+page.svelteread a detail. - The detail pages render
src/routes/characters/[characterId]/Episode.svelte,src/routes/characters/[characterId]/Location.svelteandsrc/routes/episodes/[episodeId]/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