Reach equal standing with starting template from RRv7.

This commit is contained in:
2025-03-29 20:41:49 +01:00
parent 58620c057e
commit 584ced1cd5
11 changed files with 928 additions and 137 deletions

View File

@@ -1,4 +1,11 @@
Welcome to your new TanStack app!
# TanStack/Router Address Book "RRv7 Tutorial"
This is my implementation of the React Router v7 tutorial you can
find [here](https://reactrouter.com/tutorials/address-book).
This is the
WaybackMachine: [here](https://web.archive.org/web/20250130112003/https://reactrouter.com/tutorials/address-book) at
2025-01-30.
# Getting Started
@@ -29,11 +36,10 @@ pnpm test
This project uses CSS for styling.
## Routing
This project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means that the routes are managed as files in `src/routes`.
This project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means
that the routes are managed as files in `src/routes`.
### Adding A Route
@@ -45,7 +51,8 @@ Now that you have two routes you can use a `Link` component to navigate between
### Adding Links
To use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.
To use SPA (Single Page Application) navigation you will need to import the `Link` component from
`@tanstack/react-router`.
```tsx
import { Link } from "@tanstack/react-router";
@@ -59,11 +66,13 @@ Then anywhere in your JSX you can use it like so:
This will create a link that will navigate to the `/about` route.
More information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).
More information on the `Link` component can be found in
the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).
### Using A Layout
In 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. The route content will appear in the JSX where you use the `<Outlet />` component.
In 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. The route content will appear in the JSX where you use the `<Outlet />` component.
Here is an example layout that includes a header:
@@ -82,8 +91,8 @@ export const Route = createRootRoute({
<Link to="/about">About</Link>
</nav>
</header>
<Outlet />
<TanStackRouterDevtools />
<Outlet/>
<TanStackRouterDevtools/>
</>
),
})
@@ -91,12 +100,14 @@ export const Route = createRootRoute({
The `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.
More information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).
More information on layouts can be found in
the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).
## Data Fetching
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.
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.
For example:
@@ -125,11 +136,13 @@ const peopleRoute = createRoute({
});
```
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).
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).
### React-Query
React-Query is an excellent addition or alternative to route loading and integrating it into you application is a breeze.
React-Query is an excellent addition or alternative to route loading and integrating it into you application is a
breeze.
First add your dependencies:
@@ -153,7 +166,7 @@ if (!rootElement.innerHTML) {
root.render(
<QueryClientProvider client={queryClient}>
<RouterProvider router={router} />
<RouterProvider router={router}/>
</QueryClientProvider>
);
}
@@ -167,9 +180,9 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
const rootRoute = createRootRoute({
component: () => (
<>
<Outlet />
<ReactQueryDevtools buttonPosition="top-right" />
<TanStackRouterDevtools />
<Outlet/>
<ReactQueryDevtools buttonPosition="top-right"/>
<TanStackRouterDevtools/>
</>
),
});
@@ -206,11 +219,13 @@ function App() {
export default App;
```
You can find out everything you need to know on how to use React-Query in the [React-Query documentation](https://tanstack.com/query/latest/docs/framework/react/overview).
You can find out everything you need to know on how to use React-Query in
the [React-Query documentation](https://tanstack.com/query/latest/docs/framework/react/overview).
## State Management
Another common requirement for React applications is state management. There are many options for state management in React. TanStack Store provides a great starting point for your project.
Another common requirement for React applications is state management. There are many options for state management in
React. TanStack Store provides a great starting point for your project.
First you need to add TanStack Store as a dependency:
@@ -241,7 +256,8 @@ function App() {
export default App;
```
One of the many nice features of TanStack Store is the ability to derive state from other state. That derived state will update when the base state updates.
One of the many nice features of TanStack Store is the ability to derive state from other state. That derived state will
update when the base state updates.
Let's check this out by doubling the count using derived state.
@@ -275,15 +291,19 @@ function App() {
export default App;
```
We use the `Derived` class to create a new store that is derived from another store. The `Derived` class has a `mount` method that will start the derived store updating.
We use the `Derived` class to create a new store that is derived from another store. The `Derived` class has a `mount`
method that will start the derived store updating.
Once we've created the derived store we can use it in the `App` component just like we would any other store using the `useStore` hook.
Once we've created the derived store we can use it in the `App` component just like we would any other store using the
`useStore` hook.
You can find out everything you need to know on how to use TanStack Store in the [TanStack Store documentation](https://tanstack.com/store/latest).
You can find out everything you need to know on how to use TanStack Store in
the [TanStack Store documentation](https://tanstack.com/store/latest).
# Demo files
Files 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.
Files 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.
# Learn More

View File

@@ -1,20 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="/favicon.ico" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-tsrouter-app"
/>
<link rel="apple-touch-icon" href="/logo192.png" />
<link rel="manifest" href="/manifest.json" />
<title>Create TanStack App - tsr-address-book</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="icon" href="/favicon.ico"/>
<meta
name="description"
content="TanStack/Router Address Book"
/>
<link rel="apple-touch-icon" href="/logo192.png"/>
<link rel="manifest" href="/manifest.json"/>
<title>Create TanStack App - tsr-address-book</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

View File

@@ -13,7 +13,10 @@
"@tanstack/react-router-devtools": "^1.114.3",
"@tanstack/router-plugin": "^1.114.3",
"react": "^19.0.0",
"react-dom": "^19.0.0"
"react-dom": "^19.0.0",
"match-sorter": "^8.0.0",
"sort-by": "^1.2.0",
"tiny-invariant": "^1.3.3"
},
"devDependencies": {
"@eslint/js": "^9.23.0",

35
pnpm-lock.yaml generated
View File

@@ -17,12 +17,21 @@ importers:
'@tanstack/router-plugin':
specifier: ^1.114.3
version: 1.114.30(@tanstack/react-router@1.114.29(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(vite@6.2.3(tsx@4.19.3))
match-sorter:
specifier: ^8.0.0
version: 8.0.0
react:
specifier: ^19.0.0
version: 19.1.0
react-dom:
specifier: ^19.0.0
version: 19.1.0(react@19.1.0)
sort-by:
specifier: ^1.2.0
version: 1.2.0
tiny-invariant:
specifier: ^1.3.3
version: 1.3.3
devDependencies:
'@eslint/js':
specifier: ^9.23.0
@@ -1478,6 +1487,9 @@ packages:
magic-string@0.30.17:
resolution: {integrity: sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==}
match-sorter@8.0.0:
resolution: {integrity: sha512-bGJ6Zb+OhzXe+ptP5d80OLVx7AkqfRbtGEh30vNSfjNwllu+hHI+tcbMIT/fbkx/FKN1PmKuDb65+Oofg+XUxw==}
math-intrinsics@1.1.0:
resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==}
engines: {node: '>= 0.4'}
@@ -1538,6 +1550,10 @@ packages:
resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==}
engines: {node: '>= 0.4'}
object-path@0.6.0:
resolution: {integrity: sha512-fxrwsCFi3/p+LeLOAwo/wyRMODZxdGBtUlWRzsEpsUVrisZbEfZ21arxLGfaWfcnqb8oHPNihIb4XPE8CQPN5A==}
engines: {node: '>=0.8.0'}
object.assign@4.1.7:
resolution: {integrity: sha512-nK28WOo+QIjBkDduTINE4JkF/UJJKyf2EJxvJKfblDpyg0Q+pkOHNTL0Qwy6NP6FhE/EnzV73BxxqcJaXY9anw==}
engines: {node: '>= 0.4'}
@@ -1667,6 +1683,9 @@ packages:
resolution: {integrity: sha512-dYqgNSZbDwkaJ2ceRd9ojCGjBq+mOm9LmtXnAnEGyHhN/5R7iDW2TRw3h+o/jCFxus3P2LfWIIiwowAjANm7IA==}
engines: {node: '>= 0.4'}
remove-accents@0.5.0:
resolution: {integrity: sha512-8g3/Otx1eJaVD12e31UbJj1YzdtVvzH85HV7t+9MJYk/u3XmkOUJ5Ys9wQrf9PCPK8+xn4ymzqYCiZl6QWKn+A==}
resolve-from@4.0.0:
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
engines: {node: '>=4'}
@@ -1776,6 +1795,9 @@ packages:
solid-js@1.9.5:
resolution: {integrity: sha512-ogI3DaFcyn6UhYhrgcyRAMbu/buBJitYQASZz5WzfQVPP10RD2AbCoRZ517psnezrasyCbWzIxZ6kVqet768xw==}
sort-by@1.2.0:
resolution: {integrity: sha512-aRyW65r3xMnf4nxJRluCg0H/woJpksU1dQxRtXYzau30sNBOmf5HACpDd9MZDhKh7ALQ5FgSOfMPwZEtUmMqcg==}
source-map-js@1.2.1:
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
engines: {node: '>=0.10.0'}
@@ -3649,6 +3671,11 @@ snapshots:
dependencies:
'@jridgewell/sourcemap-codec': 1.5.0
match-sorter@8.0.0:
dependencies:
'@babel/runtime': 7.27.0
remove-accents: 0.5.0
math-intrinsics@1.1.0: {}
merge2@1.4.1: {}
@@ -3690,6 +3717,8 @@ snapshots:
object-keys@1.1.1: {}
object-path@0.6.0: {}
object.assign@4.1.7:
dependencies:
call-bind: 1.0.8
@@ -3832,6 +3861,8 @@ snapshots:
gopd: 1.2.0
set-function-name: 2.0.2
remove-accents@0.5.0: {}
resolve-from@4.0.0: {}
resolve-pkg-maps@1.0.0: {}
@@ -3977,6 +4008,10 @@ snapshots:
seroval: 1.2.1
seroval-plugins: 1.2.1(seroval@1.2.1)
sort-by@1.2.0:
dependencies:
object-path: 0.6.0
source-map-js@1.2.1: {}
stackback@0.0.2: {}

View File

@@ -1,6 +1,6 @@
{
"short_name": "TanStack App",
"name": "Create TanStack App Sample",
"short_name": "TanStackRouter Address Book",
"name": "Tutorialone Address Book RR7 ma con TSR instead",
"icons": [
{
"src": "favicon.ico",
@@ -19,7 +19,5 @@
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
"display": "standalone"
}

File diff suppressed because one or more lines are too long

320
src/data.ts Normal file
View File

@@ -0,0 +1,320 @@
////////////////////////////////////////////////////////////////////////////////
// 🛑 Nothing in here has anything to do with React Router, it's just a fake database
////////////////////////////////////////////////////////////////////////////////
// noinspection UnnecessaryLocalVariableJS,JSUnusedGlobalSymbols
import { matchSorter } from "match-sorter";
// @ts-expect-error - no types, but it's a tiny function
import sortBy from "sort-by";
import invariant from "tiny-invariant";
type ContactMutation = {
id?: string;
first?: string;
last?: string;
avatar?: string;
twitter?: string;
notes?: string;
favorite?: boolean;
};
export type ContactRecord = ContactMutation & {
id: string;
createdAt: string;
};
////////////////////////////////////////////////////////////////////////////////
// This is just a fake DB table. In a real app you'd be talking to a real db or
// fetching from an existing API.
const fakeContacts = {
records: {} as Record<string, ContactRecord>,
async getAll(): Promise<ContactRecord[]> {
return Object.keys(fakeContacts.records)
.map((key) => fakeContacts.records[key])
.sort(sortBy("-createdAt", "last"));
},
async get(id: string): Promise<ContactRecord | null> {
return fakeContacts.records[id] || null;
},
async create(values: ContactMutation): Promise<ContactRecord> {
const id = values.id || Math.random().toString(36).substring(2, 9);
const createdAt = new Date().toISOString();
const newContact = { id, createdAt, ...values };
fakeContacts.records[id] = newContact;
return newContact;
},
async set(id: string, values: ContactMutation): Promise<ContactRecord> {
const contact = await fakeContacts.get(id);
invariant(contact, `No contact found for ${id}`);
const updatedContact = { ...contact, ...values };
fakeContacts.records[id] = updatedContact;
return updatedContact;
},
destroy(id: string): null {
delete fakeContacts.records[id];
return null;
},
};
////////////////////////////////////////////////////////////////////////////////
// Handful of helper functions to be called from route loaders and actions
export async function getContacts(query?: string | null) {
await new Promise((resolve) => setTimeout(resolve, 500));
let contacts = await fakeContacts.getAll();
if (query) {
contacts = matchSorter(contacts, query, {
keys: ["first", "last"],
});
}
return contacts.sort(sortBy("last", "createdAt"));
}
export async function createEmptyContact() {
const contact = await fakeContacts.create({});
return contact;
}
export async function getContact(id: string) {
return fakeContacts.get(id);
}
export async function updateContact(id: string, updates: ContactMutation) {
const contact = await fakeContacts.get(id);
if (!contact) {
throw new Error(`No contact found for ${id}`);
}
await fakeContacts.set(id, { ...contact, ...updates });
return contact;
}
export async function deleteContact(id: string) {
fakeContacts.destroy(id);
}
[
{
avatar:
"https://sessionize.com/image/124e-400o400o2-wHVdAuNaxi8KJrgtN3ZKci.jpg",
first: "Shruti",
last: "Kapoor",
twitter: "@shrutikapoor08",
},
{
avatar:
"https://sessionize.com/image/1940-400o400o2-Enh9dnYmrLYhJSTTPSw3MH.jpg",
first: "Glenn",
last: "Reyes",
twitter: "@glnnrys",
},
{
avatar:
"https://sessionize.com/image/9273-400o400o2-3tyrUE3HjsCHJLU5aUJCja.jpg",
first: "Ryan",
last: "Florence",
},
{
avatar:
"https://sessionize.com/image/d14d-400o400o2-pyB229HyFPCnUcZhHf3kWS.png",
first: "Oscar",
last: "Newman",
twitter: "@__oscarnewman",
},
{
avatar:
"https://sessionize.com/image/fd45-400o400o2-fw91uCdGU9hFP334dnyVCr.jpg",
first: "Michael",
last: "Jackson",
},
{
avatar:
"https://sessionize.com/image/b07e-400o400o2-KgNRF3S9sD5ZR4UsG7hG4g.jpg",
first: "Christopher",
last: "Chedeau",
twitter: "@Vjeux",
},
{
avatar:
"https://sessionize.com/image/262f-400o400o2-UBPQueK3fayaCmsyUc1Ljf.jpg",
first: "Cameron",
last: "Matheson",
twitter: "@cmatheson",
},
{
avatar:
"https://sessionize.com/image/820b-400o400o2-Ja1KDrBAu5NzYTPLSC3GW8.jpg",
first: "Brooks",
last: "Lybrand",
twitter: "@BrooksLybrand",
},
{
avatar:
"https://sessionize.com/image/df38-400o400o2-JwbChVUj6V7DwZMc9vJEHc.jpg",
first: "Alex",
last: "Anderson",
twitter: "@ralex1993",
},
{
avatar:
"https://sessionize.com/image/5578-400o400o2-BMT43t5kd2U1XstaNnM6Ax.jpg",
first: "Kent C.",
last: "Dodds",
twitter: "@kentcdodds",
},
{
avatar:
"https://sessionize.com/image/c9d5-400o400o2-Sri5qnQmscaJXVB8m3VBgf.jpg",
first: "Nevi",
last: "Shah",
twitter: "@nevikashah",
},
{
avatar:
"https://sessionize.com/image/2694-400o400o2-MYYTsnszbLKTzyqJV17w2q.png",
first: "Andrew",
last: "Petersen",
},
{
avatar:
"https://sessionize.com/image/907a-400o400o2-9TM2CCmvrw6ttmJiTw4Lz8.jpg",
first: "Scott",
last: "Smerchek",
twitter: "@smerchek",
},
{
avatar:
"https://sessionize.com/image/08be-400o400o2-WtYGFFR1ZUJHL9tKyVBNPV.jpg",
first: "Giovanni",
last: "Benussi",
twitter: "@giovannibenussi",
},
{
avatar:
"https://sessionize.com/image/f814-400o400o2-n2ua5nM9qwZA2hiGdr1T7N.jpg",
first: "Igor",
last: "Minar",
twitter: "@IgorMinar",
},
{
avatar:
"https://sessionize.com/image/fb82-400o400o2-LbvwhTVMrYLDdN3z4iEFMp.jpeg",
first: "Brandon",
last: "Kish",
},
{
avatar:
"https://sessionize.com/image/fcda-400o400o2-XiYRtKK5Dvng5AeyC8PiUA.png",
first: "Arisa",
last: "Fukuzaki",
twitter: "@arisa_dev",
},
{
avatar:
"https://sessionize.com/image/c8c3-400o400o2-PR5UsgApAVEADZRixV4H8e.jpeg",
first: "Alexandra",
last: "Spalato",
twitter: "@alexadark",
},
{
avatar:
"https://sessionize.com/image/7594-400o400o2-hWtdCjbdFdLgE2vEXBJtyo.jpg",
first: "Cat",
last: "Johnson",
},
{
avatar:
"https://sessionize.com/image/5636-400o400o2-TWgi8vELMFoB3hB9uPw62d.jpg",
first: "Ashley",
last: "Narcisse",
twitter: "@_darkfadr",
},
{
avatar:
"https://sessionize.com/image/6aeb-400o400o2-Q5tAiuzKGgzSje9ZsK3Yu5.JPG",
first: "Edmund",
last: "Hung",
twitter: "@_edmundhung",
},
{
avatar:
"https://sessionize.com/image/30f1-400o400o2-wJBdJ6sFayjKmJycYKoHSe.jpg",
first: "Clifford",
last: "Fajardo",
twitter: "@cliffordfajard0",
},
{
avatar:
"https://sessionize.com/image/6faa-400o400o2-amseBRDkdg7wSK5tjsFDiG.jpg",
first: "Erick",
last: "Tamayo",
twitter: "@ericktamayo",
},
{
avatar:
"https://sessionize.com/image/feba-400o400o2-R4GE7eqegJNFf3cQ567obs.jpg",
first: "Paul",
last: "Bratslavsky",
twitter: "@codingthirty",
},
{
avatar:
"https://sessionize.com/image/c315-400o400o2-spjM5A6VVfVNnQsuwvX3DY.jpg",
first: "Pedro",
last: "Cattori",
twitter: "@pcattori",
},
{
avatar:
"https://sessionize.com/image/eec1-400o400o2-HkvWKLFqecmFxLwqR9KMRw.jpg",
first: "Andre",
last: "Landgraf",
twitter: "@AndreLandgraf94",
},
{
avatar:
"https://sessionize.com/image/c73a-400o400o2-4MTaTq6ftC15hqwtqUJmTC.jpg",
first: "Monica",
last: "Powell",
twitter: "@indigitalcolor",
},
{
avatar:
"https://sessionize.com/image/cef7-400o400o2-KBZUydbjfkfGACQmjbHEvX.jpeg",
first: "Brian",
last: "Lee",
twitter: "@brian_dlee",
},
{
avatar:
"https://sessionize.com/image/f83b-400o400o2-Pyw3chmeHMxGsNoj3nQmWU.jpg",
first: "Sean",
last: "McQuaid",
twitter: "@SeanMcQuaidCode",
},
{
avatar:
"https://sessionize.com/image/a9fc-400o400o2-JHBnWZRoxp7QX74Hdac7AZ.jpg",
first: "Shane",
last: "Walker",
twitter: "@swalker326",
},
{
avatar:
"https://sessionize.com/image/6644-400o400o2-aHnGHb5Pdu3D32MbfrnQbj.jpg",
first: "Jon",
last: "Jensen",
twitter: "@jenseng",
},
].forEach((contact) => {
fakeContacts.create({
...contact,
id: `${contact.first
.toLowerCase()
.split(" ")
.join("_")}-${contact.last.toLocaleLowerCase()}`,
});
});

View File

@@ -1,12 +1,11 @@
import { StrictMode } from 'react'
import ReactDOM from 'react-dom/client'
import { RouterProvider, createRouter } from '@tanstack/react-router'
import { StrictMode } from 'react';
import ReactDOM from 'react-dom/client';
import { RouterProvider, createRouter } from '@tanstack/react-router';
// Import the generated route tree
import { routeTree } from './routeTree.gen'
import { routeTree } from './routeTree.gen';
import './styles.css'
import reportWebVitals from './reportWebVitals.ts'
import reportWebVitals from './reportWebVitals.ts';
// Create a new router instance
const router = createRouter({
@@ -16,27 +15,27 @@ const router = createRouter({
scrollRestoration: true,
defaultStructuralSharing: true,
defaultPreloadStaleTime: 0,
})
});
// Register the router instance for type safety
declare module '@tanstack/react-router' {
interface Register {
router: typeof router
router: typeof router;
}
}
// Render the app
const rootElement = document.getElementById('app')
const rootElement = document.getElementById('app');
if (rootElement && !rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement)
const root = ReactDOM.createRoot(rootElement);
root.render(
<StrictMode>
<RouterProvider router={router} />
<RouterProvider router={router}/>
</StrictMode>,
)
);
}
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals()
reportWebVitals();

View File

@@ -1,11 +1,21 @@
import { Outlet, createRootRoute } from '@tanstack/react-router'
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
import { Outlet, createRootRoute } from '@tanstack/react-router';
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools';
export const Route = createRootRoute({
component: () => (
<>
<Outlet />
<TanStackRouterDevtools />
<Outlet/>
<TanStackRouterDevtools/>
</>
),
})
notFoundComponent: NotFoundComponent,
});
function NotFoundComponent() {
return (
<main id="error-page">
<h1>404</h1>
<p>The requested page could not be found.</p>
</main>
);
}

View File

@@ -1,36 +1,41 @@
import { createFileRoute } from '@tanstack/react-router'
import logo from '../logo.svg'
import '../App.css'
import { createFileRoute } from '@tanstack/react-router';
import '../App.css';
export const Route = createFileRoute('/')({
component: App,
})
});
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/routes/index.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
<a
className="App-link"
href="https://tanstack.com"
target="_blank"
rel="noopener noreferrer"
>
Learn TanStack
</a>
</header>
</div>
)
<>
<div id="sidebar">
<h1>React Router Contacts</h1>
<div>
<form id="search-form" role="search">
<input
aria-label="Search contacts"
id="q"
name="q"
placeholder="Search"
type="search"
/>
<div aria-hidden hidden={true} id="search-spinner"/>
</form>
<form method="post">
<button type="submit">New</button>
</form>
</div>
<nav>
<ul>
<li>
<a href={`/contacts/1`}>Your Name</a>
</li>
<li>
<a href={`/contacts/2`}>Your Friend</a>
</li>
</ul>
</nav>
</div>
</>
);
}

View File

@@ -1,14 +0,0 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}