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

README.md.ejs

166 lines5.2 KB

1<% if (blank) { -%>
2# <%= projectName %>
3​
4A minimal TanStack Start app with one route and <%= tailwind ? 'Tailwind CSS' : 'plain CSS' %>.
5​
6```bash
7<%= packageManager %> install
8<%= getPackageManagerRunScript('dev') %>
9```
10​
11Edit `src/routes/index.tsx` to get started. Add route files under
12`src/routes`; TanStack Router updates `src/routeTree.gen.ts` for you.
13​
14Build the production app with:
15​
16```bash
17<%= getPackageManagerRunScript('build') %>
18```
19<% for(const addon of addOns.filter(addon => addon.readme)) { %>
20<%- addon.readmeIsEjs ? renderTemplate(addon.readme) : addon.readme %>
21<% } %>
22<% } else { -%>
23Welcome to your new TanStack Start app!
24​
25# Getting Started
26​
27To run this application:
28​
29```bash
30<%= packageManager %> install
31<%= getPackageManagerRunScript('dev') %>
32```
33​
34# Building For Production
35​
36To build this application for production:
37​
38```bash
39<%= getPackageManagerRunScript('build') %>
40```
41​
42## Styling
43​
44This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
45​
46### Removing Tailwind CSS
47​
48If you prefer not to use Tailwind CSS:
49​
501. Remove the demo pages in `src/routes/demo/`
512. Replace the Tailwind import in `src/styles.css` with your own styles
523. Remove `<%= bundler === 'vite' ? 'tailwindcss()' : 'pluginTailwindcss()' %>` from the plugins array in `<%= bundler %>.config.ts`
534. Remove `<%= bundler === 'vite' ? '@tailwindcss/vite' : '@rsbuild/plugin-tailwindcss' %>` and `tailwindcss` from `package.json`
54​
55<% for(const addon of addOns.filter(addon => addon.readme)) { %>
56<%- addon.readmeIsEjs ? renderTemplate(addon.readme) : addon.readme %>
57<% } %>
58​
59## Routing
60​
61This project uses [TanStack Router](https://tanstack.com/router) with file-based routing. Routes are managed as files in `src/routes`.
62​
63### Adding A Route
64​
65To add a new route to your application just add a new file in the `./src/routes` directory.
66​
67TanStack will automatically generate the content of the route file for you.
68​
69Now that you have two routes you can use a `Link` component to navigate between them.
70​
71### Adding Links
72​
73To use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/solid-router`.
74​
75```tsx
76import { Link } from "@tanstack/solid-router";
77```
78​
79Then anywhere in your JSX you can use it like so:
80​
81```tsx
82<Link to="/about">About</Link>
83```
84​
85This will create a link that will navigate to the `/about` route.
86​
87More information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/solid/api/router/linkComponent).
88​
89### Using A Layout
90​
91In 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.
92​
93More information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/solid/guide/routing-concepts#layouts).
94​
95## Server Functions
96​
97TanStack Start provides server functions that allow you to write server-side code that seamlessly integrates with your client components.
98​
99```tsx
100import { createServerFn } from '@tanstack/solid-start'
101​
102const getServerTime = createServerFn({
103 method: 'GET',
104}).handler(async () => {
105 return new Date().toISOString()
106})
107```
108​
109## Data Fetching
110​
111There 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.
112​
113For example:
114​
115```tsx
116import { createFileRoute } from '@tanstack/solid-router'
117​
118export const Route = createFileRoute('/people')({
119 loader: async () => {
120 const response = await fetch('https://swapi.dev/api/people')
121 return response.json()
122 },
123 component: PeopleComponent,
124})
125​
126function PeopleComponent() {
127 const data = Route.useLoaderData()
128 return (
129 <ul>
130 <For each={data().results}>
131 {(person) => <li>{person.name}</li>}
132 </For>
133 </ul>
134 )
136```
137​
138Loaders 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).
139​
140<% if (includeExamples) { %>
141# Demo files
142​
143Files 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.
144<% } %>
145​
146<% if (addOnEnabled.biome || addOnEnabled.eslint) { %>
147## Linting & Formatting
148<% if (addOnEnabled.biome) { %>
149This project uses [Biome](https://biomejs.dev/) for linting and formatting. The following scripts are available:
150<% } %>
151<% if (addOnEnabled.eslint) { %>
152This project uses [eslint](https://eslint.org/) and [prettier](https://prettier.io/) for linting and formatting. Eslint is configured using [tanstack/eslint-config](https://tanstack.com/config/latest/docs/eslint). The following scripts are available:
153<% } %>
154```bash
155<%= getPackageManagerRunScript('lint') %>
156<%= getPackageManagerRunScript('format') %>
157<%= getPackageManagerRunScript('check') %>
158```
159<% } %>
160​
161# Learn More
162​
163You can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).
164​
165For TanStack Start specific documentation, visit [TanStack Start](https://tanstack.com/start).
166<% } -%>