|
| 1 | +import ReactDOM from 'react-dom/client' |
| 2 | +import * as Sentry from '@sentry/react' |
| 3 | +import { |
| 4 | + Link, |
| 5 | + Outlet, |
| 6 | + RouterProvider, |
| 7 | + createRootRoute, |
| 8 | + createRoute, |
| 9 | + createRouter, |
| 10 | +} from '@tanstack/react-router' |
| 11 | +import { TanStackRouterDevtools } from '@tanstack/router-devtools' |
| 12 | +import './styles.css' |
| 13 | + |
| 14 | +const rootRoute = createRootRoute({ |
| 15 | + component: RootComponent, |
| 16 | + notFoundComponent: () => { |
| 17 | + return ( |
| 18 | + <div> |
| 19 | + <p>This is the notFoundComponent configured on root route</p> |
| 20 | + <Link to="/">Start Over</Link> |
| 21 | + </div> |
| 22 | + ) |
| 23 | + }, |
| 24 | +}) |
| 25 | + |
| 26 | +function RootComponent() { |
| 27 | + return ( |
| 28 | + <> |
| 29 | + <div className="p-2 flex gap-2 text-lg border-b"> |
| 30 | + <Link |
| 31 | + to="/" |
| 32 | + activeProps={{ |
| 33 | + className: 'font-bold', |
| 34 | + }} |
| 35 | + activeOptions={{ exact: true }} |
| 36 | + > |
| 37 | + Home |
| 38 | + </Link> |
| 39 | + </div> |
| 40 | + <Outlet /> |
| 41 | + <TanStackRouterDevtools position="bottom-right" /> |
| 42 | + </> |
| 43 | + ) |
| 44 | +} |
| 45 | +const indexRoute = createRoute({ |
| 46 | + getParentRoute: () => rootRoute, |
| 47 | + path: '/', |
| 48 | + component: IndexComponent, |
| 49 | +}) |
| 50 | + |
| 51 | +function IndexComponent() { |
| 52 | + return ( |
| 53 | + <div className="p-2"> |
| 54 | + <h3>Welcome Home!</h3> |
| 55 | + </div> |
| 56 | + ) |
| 57 | +} |
| 58 | + |
| 59 | +const routeTree = rootRoute.addChildren([indexRoute]) |
| 60 | + |
| 61 | +// Set up a Router instance |
| 62 | +const router = createRouter({ |
| 63 | + routeTree, |
| 64 | + defaultPreload: 'intent', |
| 65 | + defaultStaleTime: 5000, |
| 66 | +}) |
| 67 | + |
| 68 | +// Register things for typesafety |
| 69 | +declare module '@tanstack/react-router' { |
| 70 | + interface Register { |
| 71 | + router: typeof router |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +Sentry.init({ |
| 76 | + dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0', |
| 77 | + integrations: [Sentry.tanstackRouterBrowserTracingIntegration(router)], |
| 78 | + transport: () => ({ |
| 79 | + send: (): Promise<any> => Promise.resolve(), |
| 80 | + flush: () => Promise.resolve(true), |
| 81 | + }), |
| 82 | + tracesSampleRate: 0.2, |
| 83 | + sendClientReports: false, |
| 84 | +}) |
| 85 | + |
| 86 | +const rootElement = document.getElementById('app')! |
| 87 | + |
| 88 | +if (!rootElement.innerHTML) { |
| 89 | + const root = ReactDOM.createRoot(rootElement) |
| 90 | + |
| 91 | + root.render(<RouterProvider router={router} />) |
| 92 | +} |
0 commit comments