Skip to content
Source
Sign inSign up
TanStack/cli
Open History to see the last commit

README.md

126 lines3.5 KB

1Welcome to your new TanStack Start app!
2​
3# Getting Started
4​
5To run this application:
6​
7```bash
8npm install
9npm run dev
10```
11​
12# Building For Production
13​
14To build this application for production:
15​
16```bash
17npm run build
18```
19​
20## Styling
21​
22This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
23​
24### Removing Tailwind CSS
25​
26If you prefer not to use Tailwind CSS:
27​
281. Remove the demo pages in `src/routes/demo/`
292. Replace the Tailwind import in `src/styles.css` with your own styles
303. Remove `tailwindcss()` from the plugins array in `vite.config.ts`
314. Uninstall the packages: `npm install @tailwindcss/vite tailwindcss -D`
32​
33​
34​
35## Routing
36​
37This project uses [TanStack Router](https://tanstack.com/router) with file-based routing. Routes are managed as files in `src/routes`.
38​
39### Adding A Route
40​
41To add a new route to your application just add a new file in the `./src/routes` directory.
42​
43TanStack will automatically generate the content of the route file for you.
44​
45Now that you have two routes you can use a `Link` component to navigate between them.
46​
47### Adding Links
48​
49To use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/solid-router`.
50​
51```tsx
52import { Link } from "@tanstack/solid-router";
53```
54​
55Then anywhere in your JSX you can use it like so:
56​
57```tsx
58<Link to="/about">About</Link>
59```
60​
61This will create a link that will navigate to the `/about` route.
62​
63More information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/solid/api/router/linkComponent).
64​
65### Using A Layout
66​
67In the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes.
68​
69More information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/solid/guide/routing-concepts#layouts).
70​
71## Server Functions
72​
73TanStack Start provides server functions that allow you to write server-side code that seamlessly integrates with your client components.
74​
75```tsx
76import { createServerFn } from '@tanstack/solid-start'
77​
78const getServerTime = createServerFn({
79 method: 'GET',
80}).handler(async () => {
81 return new Date().toISOString()
82})
83```
84​
85## Data Fetching
86​
87There 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.
88​
89For example:
90​
91```tsx
92import { createFileRoute } from '@tanstack/solid-router'
93​
94export const Route = createFileRoute('/people')({
95 loader: async () => {
96 const response = await fetch('https://swapi.dev/api/people')
97 return response.json()
98 },
99 component: PeopleComponent,
100})
101​
102function PeopleComponent() {
103 const data = Route.useLoaderData()
104 return (
105 <ul>
106 <For each={data().results}>
107 {(person) => <li>{person.name}</li>}
108 </For>
109 </ul>
110 )
112```
113​
114Loaders simplify your data fetching logic dramatically. Check out more information in the [Loader documentation](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#loader-parameters).
115​
116# Demo files
117​
118Files prefixed with `demo` can be safely deleted. They are there to provide a starting point for you to play around with the features you've installed.
119​
120​
121​
122# Learn More
123​
124You can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).
125​
126For TanStack Start specific documentation, visit [TanStack Start](https://tanstack.com/start).