Skip to content

Commit 012761f

Browse files
authored
docs: modernize TanStack tutorial to current Router API (#3410)
1 parent 4d7444e commit 012761f

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

examples/tutorials/tanstack.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
last_modified: 2025-03-10
2+
last_modified: 2026-07-10
33
title: "Build an app with Tanstack and Deno"
44
description: "Complete guide to building applications with Tanstack and Deno. Learn how to implement Query for data fetching, Router for navigation, manage server state, and create type-safe full-stack applications."
55
url: /examples/tanstack_tutorial/
@@ -232,7 +232,7 @@ export function DinosaurList() {
232232
```
233233

234234
This uses
235-
[`useQuery`](https://tanstack.com/query/v4/docs/framework/react/guides/queries)
235+
[`useQuery`](https://tanstack.com/query/latest/docs/framework/react/guides/queries)
236236
from **Tanstack Query** to fetch and cache the dinosaur data automatically, with
237237
built-in loading and error states. Then it uses
238238
[`Link`](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent)
@@ -295,6 +295,8 @@ Let's create another file in the `./src/components/` folder called `Layout.tsx`:
295295
```ts
296296
// ./src/components/Layout.tsx
297297

298+
import { Link, Outlet } from "@tanstack/react-router";
299+
298300
export function Layout() {
299301
return (
300302
<div className="p-4">
@@ -362,22 +364,22 @@ structure using Tanstack Router's type-safe route definitions:
362364
```ts
363365
// ./src/routeTree.tsx
364366

365-
import { RootRoute, Route } from "@tanstack/react-router";
367+
import { createRootRoute, createRoute } from "@tanstack/react-router";
366368
import { DinosaurList } from "./components/DinosaurList";
367369
import { DinosaurDetail } from "./components/DinosaurDetail";
368370
import { Layout } from "./components/Layout";
369371

370-
const rootRoute = new RootRoute({
372+
const rootRoute = createRootRoute({
371373
component: Layout,
372374
});
373375

374-
const indexRoute = new Route({
376+
const indexRoute = createRoute({
375377
getParentRoute: () => rootRoute,
376378
path: "/",
377379
component: DinosaurList,
378380
});
379381

380-
const dinosaurRoute = new Route({
382+
const dinosaurRoute = createRoute({
381383
getParentRoute: () => rootRoute,
382384
path: "dinosaur/$name",
383385
component: DinosaurDetail,
@@ -386,10 +388,11 @@ const dinosaurRoute = new Route({
386388
export const routeTree = rootRoute.addChildren([indexRoute, dinosaurRoute]);
387389
```
388390

389-
In `./src/routeTree.tsx`, we create a hierarchy of routes with `Layout` as the
390-
root component. Then we set two child routes, their paths and components — one
391-
for the dinosaur list, `DinosaurList`, and the other for the individual dinosaur
392-
details with a dynamic parameter, `DinosaurDetail`.
391+
In `./src/routeTree.tsx`, we use `createRootRoute` to create a route hierarchy
392+
with `Layout` as the root component. Then `createRoute` sets two child routes,
393+
their paths and components: one for the dinosaur list, `DinosaurList`, and the
394+
other for the individual dinosaur details with a dynamic parameter,
395+
`DinosaurDetail`.
393396

394397
With all that complete, we can run this project:
395398

0 commit comments

Comments
 (0)