Skip to content

Commit

Permalink
migrate to tanstack/react-router
Browse files Browse the repository at this point in the history
  • Loading branch information
ASafaeirad committed Aug 13, 2024
1 parent a17386e commit 0ee27ad
Show file tree
Hide file tree
Showing 59 changed files with 787 additions and 366 deletions.
1 change: 1 addition & 0 deletions @types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/// <reference path="./mantine.d.ts" />
/// <reference path="./svg.d.ts" />
/// <reference path="./vite-env.d.ts" />
/// <reference path="./router.d.ts" />
/// <reference types="@total-typescript/ts-reset" />
10 changes: 10 additions & 0 deletions @types/router.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare module '@tanstack/react-router' {
interface Register {
router: typeof import('../app/main').router;
}
type AllRouteIds = import('@tanstack/react-router').RouteIds<
typeof import('../app/routeTree.gen').routeTree
>;
}

export {};
82 changes: 0 additions & 82 deletions app/Routes.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions app/index.ts

This file was deleted.

35 changes: 23 additions & 12 deletions app/main.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import 'dayjs/locale/fa';
import '@camp/zod-addons/monkey-patch';
import 'dayjs/locale/fa';

import { ApolloProvider } from '@camp/api-client';
import { AuthProvider } from '@camp/auth';
import { config } from '@camp/config';
import { debug, DebugScopes } from '@camp/debug';
import { ThemeProvider } from '@camp/design';
import type { AllRouteIds } from '@camp/router';
import { createRouter, RouterProvider } from '@camp/router';
import { StrictMode } from 'react';
import ReactDOM from 'react-dom/client';

import { Routes } from './Routes';
import { routeTree } from './routeTree.gen';

export interface RouterContext {
getTitle: (to: AllRouteIds) => string;
}

export const router = createRouter({
routeTree,
context: {
getTitle: x => {
const routeTitles: Partial<Record<AllRouteIds, string>> = {
'/dashboard/_layout/households/_layout': 'خانوار',
'/dashboard/_layout/households/_layout/$householdId': 'خانواده',
};

return routeTitles[x] ?? '';
},
},
});

const root = ReactDOM.createRoot(document.getElementById('root')!);
debug.log(DebugScopes.All, config);

root.render(
<StrictMode>
<AuthProvider>
<ApolloProvider>
<ThemeProvider>
<Routes />
</ThemeProvider>
</ApolloProvider>
</AuthProvider>
<RouterProvider router={router} />
</StrictMode>,
);
Loading

0 comments on commit 0ee27ad

Please sign in to comment.