Skip to content

Commit 6a66316

Browse files
authored
fix: tanstack router (#25)
* fix: tanstack router * remove unused import
1 parent de0172f commit 6a66316

File tree

8 files changed

+66
-29
lines changed

8 files changed

+66
-29
lines changed

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default [
1010
eslintPluginPrettierRecommended,
1111
tseslint.configs.eslintRecommended,
1212
{
13-
ignores: ['**/dist', '.prettierrc.js'],
13+
ignores: ['**/dist', '.prettierrc.js', '**/routeTree.gen.ts'],
1414
},
1515
{
1616
plugins: {

src/components/App/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
text-align: center;
33

44
.app-header {
5-
min-height: 80vh;
5+
min-height: 100vh;
66
display: flex;
77
flex-direction: column;
88
align-items: center;

src/components/App/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { QueryExample } from '../QueryExample';
2-
31
import './App.css';
42

53
export default function App() {
@@ -8,7 +6,6 @@ export default function App() {
86
<header className="app-header">
97
<h1>Hello World</h1>
108
</header>
11-
<QueryExample />
129
</main>
1310
);
1411
}

src/index.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { StrictMode } from 'react';
22
import { createRoot } from 'react-dom/client';
33
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
4-
import App from './components/App';
4+
import { createRouter, RouterProvider } from '@tanstack/react-router';
5+
6+
import { routeTree } from './routeTree.gen';
57

6-
const rootElement = document.getElementById('root');
78
const queryClient = new QueryClient();
9+
const router = createRouter({ routeTree });
810

9-
if (rootElement) {
11+
declare module '@tanstack/react-router' {
12+
interface Register {
13+
router: typeof router;
14+
}
15+
}
16+
17+
const rootElement = document.getElementById('root');
18+
if (rootElement && !rootElement.innerHTML) {
1019
createRoot(rootElement).render(
1120
<StrictMode>
1221
<QueryClientProvider client={queryClient}>
13-
<App />
22+
<RouterProvider router={router} />
1423
</QueryClientProvider>
1524
</StrictMode>
1625
);

src/routeTree.gen.ts

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,25 @@ import { createFileRoute } from '@tanstack/react-router'
1313
// Import Routes
1414

1515
import { Route as rootRoute } from './routes/__root'
16+
import { Route as IndexImport } from './routes/index'
1617

1718
// Create Virtual Routes
1819

19-
const IndexLazyImport = createFileRoute('/')()
20+
const QueryLazyImport = createFileRoute('/query')()
2021

2122
// Create/Update Routes
2223

23-
const IndexLazyRoute = IndexLazyImport.update({
24+
const QueryLazyRoute = QueryLazyImport.update({
25+
id: '/query',
26+
path: '/query',
27+
getParentRoute: () => rootRoute,
28+
} as any).lazy(() => import('./routes/query.lazy').then((d) => d.Route))
29+
30+
const IndexRoute = IndexImport.update({
2431
id: '/',
2532
path: '/',
2633
getParentRoute: () => rootRoute,
27-
} as any).lazy(() => import('./routes/index.lazy').then((d) => d.Route))
34+
} as any)
2835

2936
// Populate the FileRoutesByPath interface
3037

@@ -34,7 +41,14 @@ declare module '@tanstack/react-router' {
3441
id: '/'
3542
path: '/'
3643
fullPath: '/'
37-
preLoaderRoute: typeof IndexLazyImport
44+
preLoaderRoute: typeof IndexImport
45+
parentRoute: typeof rootRoute
46+
}
47+
'/query': {
48+
id: '/query'
49+
path: '/query'
50+
fullPath: '/query'
51+
preLoaderRoute: typeof QueryLazyImport
3852
parentRoute: typeof rootRoute
3953
}
4054
}
@@ -43,33 +57,38 @@ declare module '@tanstack/react-router' {
4357
// Create and export the route tree
4458

4559
export interface FileRoutesByFullPath {
46-
'/': typeof IndexLazyRoute
60+
'/': typeof IndexRoute
61+
'/query': typeof QueryLazyRoute
4762
}
4863

4964
export interface FileRoutesByTo {
50-
'/': typeof IndexLazyRoute
65+
'/': typeof IndexRoute
66+
'/query': typeof QueryLazyRoute
5167
}
5268

5369
export interface FileRoutesById {
5470
__root__: typeof rootRoute
55-
'/': typeof IndexLazyRoute
71+
'/': typeof IndexRoute
72+
'/query': typeof QueryLazyRoute
5673
}
5774

5875
export interface FileRouteTypes {
5976
fileRoutesByFullPath: FileRoutesByFullPath
60-
fullPaths: '/'
77+
fullPaths: '/' | '/query'
6178
fileRoutesByTo: FileRoutesByTo
62-
to: '/'
63-
id: '__root__' | '/'
79+
to: '/' | '/query'
80+
id: '__root__' | '/' | '/query'
6481
fileRoutesById: FileRoutesById
6582
}
6683

6784
export interface RootRouteChildren {
68-
IndexLazyRoute: typeof IndexLazyRoute
85+
IndexRoute: typeof IndexRoute
86+
QueryLazyRoute: typeof QueryLazyRoute
6987
}
7088

7189
const rootRouteChildren: RootRouteChildren = {
72-
IndexLazyRoute: IndexLazyRoute,
90+
IndexRoute: IndexRoute,
91+
QueryLazyRoute: QueryLazyRoute,
7392
}
7493

7594
export const routeTree = rootRoute
@@ -82,11 +101,15 @@ export const routeTree = rootRoute
82101
"__root__": {
83102
"filePath": "__root.tsx",
84103
"children": [
85-
"/"
104+
"/",
105+
"/query"
86106
]
87107
},
88108
"/": {
89-
"filePath": "index.lazy.tsx"
109+
"filePath": "index.tsx"
110+
},
111+
"/query": {
112+
"filePath": "query.lazy.tsx"
90113
}
91114
}
92115
}

src/routes/index.lazy.tsx

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/routes/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createFileRoute } from '@tanstack/react-router';
2+
3+
import App from '../components/App';
4+
5+
export const Route = createFileRoute('/')({
6+
component: App,
7+
});

src/routes/query.lazy.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createLazyFileRoute } from '@tanstack/react-router';
2+
3+
import { QueryExample } from '../components/QueryExample';
4+
5+
export const Route = createLazyFileRoute('/query')({
6+
component: QueryExample,
7+
});

0 commit comments

Comments
 (0)