You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: project-template/README.md
+150-2Lines changed: 150 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,6 +67,8 @@ Then anywhere in your JSX you can use it like so:
67
67
68
68
This will create a link that will navigate to the `/about` route.
69
69
70
+
More information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).
71
+
70
72
### Using A Layout
71
73
72
74
Layouts can be used to wrap the contents of the routes in menus, headers, footers, etc.
The `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.
107
109
110
+
More information on layouts can be found in the [Layouts documentation](hthttps://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).
111
+
112
+
### Migrating To File Base Routing
113
+
114
+
First you need to add the Vite plugin for Tanstack Router:
115
+
116
+
```bash
117
+
npm install -D @tanstack/router-plugin
118
+
```
119
+
120
+
From there you need to update your `vite.config.ts` file to use the plugin:
At this point you can delete `src/App.tsx`, you will no longer need it as the contents have moved into `src/routes/index.tsx`.
203
+
204
+
The only additional code is the `createFileRoute` function that tells TanStack Router where to render the route. Helpfully the Vite plugin will keep the path argument that goes to `createFileRoute` automatically in sync with the file system.
205
+
206
+
Finally the `src/main.tsx` file can be simplified down to this:
// If you want to start measuring performance in your app, pass a function
241
+
// to log results (for example: reportWebVitals(console.log))
242
+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
243
+
reportWebVitals();
244
+
```
245
+
246
+
Now you've got a file based routing setup in your project! Let's have some fun with it! Just create a file in `about.tsx` in `src/routes` and it if the application is running TanStack will automatically add contents to the file and you'll have the start of your `/about` route ready to go with no additional work. You can see why folks find File Based Routing so easy to use.
247
+
248
+
You can find out everything you need to know on how to use file based routing in the [File Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/file-based-routing) documentation.
249
+
108
250
## Data Fetching
109
251
110
252
There are multiple ways to fetch data in your application. You can use TanStack Query to fetch data from a server. But you can also use the `loader` functionality built into TanStack Router to load the data for a route before it's rendered.
Loaders simplify your data fetching logic dramatically. Check out more information in the [Loader documentation](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#loader-parameters).
0 commit comments