Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

main.tsx

61 lines1.1 KB

1import React, { StrictMode } from 'react'
2import ReactDOM from 'react-dom/client'
3import {
4 Outlet,
5 RouterProvider,
6 Link,
7 createReactRouter,
8 createRouteConfig,
9} from '@tanstack/react-router'
10​
11const rootRoute = createRouteConfig({
12 component: () => (
13 <>
14 <div>
15 <Link to="/">Home</Link> <Link to="/about">About</Link>
16 </div>
17 <hr />
18 <Outlet />
19 </>
20 ),
21})
22​
23const indexRoute = rootRoute.createRoute({
24 path: '/',
25 component: Index,
26})
27​
28const aboutRoute = rootRoute.createRoute({
29 path: '/about',
30 component: About,
31})
32​
33const routeConfig = rootRoute.addChildren([indexRoute, aboutRoute])
34​
35const router = createReactRouter({ routeConfig })
36​
37function App() {
38 return <RouterProvider router={router} />
40​
41function Index() {
42 return (
43 <div>
44 <h3>Welcome Home!</h3>
45 </div>
46 )
48​
49function About() {
50 return <div>Hello from About!</div>
52​
53const rootElement = document.getElementById('app')!
54if (!rootElement.innerHTML) {
55 const root = ReactDOM.createRoot(rootElement)
56 root.render(
57 <StrictMode>
58 <App />
59 </StrictMode>,
60 )