Open History to see the last commit
1# TanStack React Query Rick And Morty Example (React Router)
2β
3A multi-page Rick and Morty app with characters and episodes, where each page fetches its own data.
4β
5Built with [React Router](https://reactrouter.com).
6β
7## How it works
8β
9- `src/services/characters/queries.ts`, `src/services/episodes/queries.ts`, and `src/services/locations/queries.ts` define `charactersQueries`, `episodesQueries`, and `locationsQueries` with `queryOptions`, each keyed under its own domain and fetching from the Rick and Morty API.
10- `src/Layout.tsx` maps the React Router routes to `src/Episodes.tsx`, `src/Episode.tsx`, `src/Characters.tsx`, and `src/Character.tsx`, and each page calls `useQuery` with the `list()` or `detail(id)` options it needs.
11- `src/Character.tsx` renders an `Episode` and a `Location` component that each call `useQuery` with their own detail options, and `src/Episode.tsx` does the same for each character. A character or episode opened from one page is already cached when the other page needs it.
12β
13To run this example:
14β
15- `npm install`
16- `npm run dev`