Skip to content

Commit

Permalink
chore: setup tanstack/router
Browse files Browse the repository at this point in the history
  • Loading branch information
ctjhoa committed Jan 22, 2024
1 parent 3ba1bbf commit 5f705c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
20 changes: 19 additions & 1 deletion apps/console/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type User, useAuth0 } from '@auth0/auth0-react'
import { GTMProvider } from '@elgorditosalsero/react-gtm-hook'
import { NotFoundRoute, Router, RouterProvider } from '@tanstack/react-router'
import axios from 'axios'
import LogRocket from 'logrocket'
import posthog from 'posthog-js'
Expand All @@ -12,14 +13,30 @@ import { PageLogin, PageLogoutFeature } from '@qovery/pages/login'
import { useAuth, useInviteMember } from '@qovery/shared/auth'
import { ProtectedRoute } from '@qovery/shared/router'
import { HELM_DEFAULT_VALUES, LOGIN_URL, LOGOUT_URL, PREVIEW_CODE } from '@qovery/shared/routes'
import { rootRoute, routeTree } from '@qovery/shared/routes'
import { LoadingScreen } from '@qovery/shared/ui'
import { useDocumentTitle } from '@qovery/shared/util-hooks'
import { useAuthInterceptor } from '@qovery/shared/utils'
import { environment } from '../environments/environment'
import { queryClient } from '../query-client'
import PreviewCode from './components/preview-code'
import ScrollToTop from './components/scroll-to-top'
import { ROUTER } from './router/main.router'

const notFoundRoute = new NotFoundRoute({
getParentRoute: () => rootRoute,
component: () => <Navigate replace to={LOGIN_URL} />,
})

const router = new Router({ routeTree, context: { queryClient }, notFoundRoute })

// Register things for typesafety
declare module '@tanstack/react-router' {
interface Register {
router: typeof router
}
}

export function App() {
useDocumentTitle('Loading...')
const { isLoading } = useAuth()
Expand Down Expand Up @@ -122,7 +139,8 @@ export function App() {
/>
)
)}
<Route path="*" element={<Navigate replace to={LOGIN_URL} />} />
{/** NOTE: Delegate remaining routing to @tanstack/router **/}
<Route path="*" element={<RouterProvider router={router} />} />
</Routes>
</GTMProvider>
)
Expand Down
2 changes: 2 additions & 0 deletions libs/shared/routes/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './lib/router'
export { routeTree } from './lib/route-tree.gen'
export { Route as rootRoute } from './lib/routes/__root'
8 changes: 8 additions & 0 deletions libs/shared/routes/src/lib/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { QueryClient } from '@tanstack/react-query'
import { Outlet, rootRouteWithContext } from '@tanstack/react-router'

export const Route = rootRouteWithContext<{
queryClient: QueryClient
}>()({
component: () => <Outlet />,
})

0 comments on commit 5f705c5

Please sign in to comment.