Open History to see the last commit
1---
2title: Devtools
3---
4β
5> Link, take this sword... I mean Devtools!... to help you on your way!
6β
7Wave your hands in the air and shout hooray because TanStack Router comes with dedicated devtools! π₯³
8β
9When you begin your TanStack Router journey, you'll want these devtools by your side. They help visualize all of the inner workings of TanStack Router and will likely save you hours of debugging if you find yourself in a pinch!
10β
11> Please note that for now, the devtools **are only supported in React**. If you would like to help us make the devtools platform-agnostic, please let us know!
12β
13## Installation
14β
15The devtools are a separate package that you need to install:
16β
17```sh
18npm install -D @tanstack/router-devtools
19```
20β
21or
22β
23```sh
24pnpm add -D @tanstack/router-devtools
25```
26β
27or
28β
29```sh
30yarn add -D @tanstack/router-devtools
31```
32β
33or
34β
35```sh
36bun add -D @tanstack/router-devtools
37```
38β
39## Import the Devtools
40β
41```js
42import { TanStackRouterDevtools } from '@tanstack/router-devtools'
43```
44β
45## Only importing and using Devtools in Development
46β
47To do this, simply use `React.lazy` and the env variable of your choice to optionally return a dummy component:
48β
49```tsx
50const TanStackRouterDevtools =
51 process.env.NODE_ENV === 'production'
52 ? () => null // Render nothing in production
53 : React.lazy(() =>
54 // Lazy load in development
55 import('@tanstack/router-devtools').then((res) => ({
56 default: res.TanStackRouterDevtools,
57 // For Embedded Mode
58 // default: res.TanStackRouterDevtoolsPanel
59 })),
60 )
61```
62β
63Then wrap the `TanStackRouterDevtools` component in suspense.
64β
65```tsx
66<Suspense>
67 <TanStackRouterDevtools />
68</Suspense>
69```
70β
71## Using inside of the `RouterProvider`
72β
73The easiest way for the devtools to work is to render them inside of your root route (or any other route). This will automatically connect the devtools to the router instance.
74β
75```tsx
76const rootRoute = createRootRoute({
77 component: () => (
78 <>
79 <Outlet />
80 <TanStackRouterDevtools />
81 </>
82 ),
83})
84β
85const routeTree = rootRoute.addChildren([
86 // ... other routes
87])
88β
89const router = createRouter({
90 routeTree,
91})
92β
93function App() {
94 return <RouterProvider router={router} />
95}
96```
97β
98## Manually passing the Router Instance
99β
100If rendering the devtools inside of the `RouterProvider` isn't your cup of tea, a `router` prop for the devtools accepts the same `router` instance you pass to the `Router` component. This makes it possible to place the devtools anywhere on the page, not just inside the provider:
101β
102```tsx
103function App() {
104 return (
105 <>
106 <RouterProvider router={router} />
107 <TanStackRouterDevtools router={router} />
108 </>
109 )
110}
111```
112β
113## Floating Mode
114β
115Floating Mode will mount the devtools as a fixed, floating element in your app and provide a toggle in the corner of the screen to show and hide the devtools. This toggle state will be stored and remembered in localStorage across reloads.
116β
117Place the following code as high in your React app as you can. The closer it is to the root of the page, the better it will work!
118β
119```js
120import { TanStackRouterDevtools } from '@tanstack/router-devtools'
121β
122function App() {
123 return (
124 <>
125 <Router />
126 <TanStackRouterDevtools initialIsOpen={false} />
127 </>
128 )
129}
130```
131β
132### Options
133β
134- `router: Router`
135 - The router instance to connect to
136- `initialIsOpen: Boolean`
137 - Set this `true` if you want the devtools to default to being open
138- `panelProps: PropsObject`
139 - Use this to add props to the panel. For example, you can add `className`, `style` (merge and override default style), etc.
140- `closeButtonProps: PropsObject`
141 - Use this to add props to the close button. For example, you can add `className`, `style` (merge and override default style), `onClick` (extend default handler), etc.
142- `toggleButtonProps: PropsObject`
143 - Use this to add props to the toggle button. For example, you can add `className`, `style` (merge and override default style), `onClick` (extend default handler), etc.
144- `position?: "top-left" | "top-right" | "bottom-left" | "bottom-right"`
145 - Defaults to `bottom-left`
146 - The position of the TanStack Router logo to open and close the devtools panel
147- `shadowDOMTarget?: ShadowRoot`
148 - Specifies a Shadow DOM target for the devtools.
149 - By default, devtool styles are applied to the `<head>` tag of the main document (light DOM). When a `shadowDOMTarget` is provided, styles will be applied within this Shadow DOM instead.
150β
151## Embedded Mode
152β
153Embedded Mode will embed the devtools as a regular component in your application. You can style it however you'd like after that!
154β
155```js
156import { TanStackRouterDevtoolsPanel } from '@tanstack/router-devtools'
157β
158function App() {
159 return (
160 <>
161 <Router router={router} />
162 <TanStackRouterDevtoolsPanel
163 router={router}
164 style={styles}
165 className={className}
166 />
167 </>
168 )
169}
170```
171β
172### Options
173β
174Use these options to style the devtools.
175β
176- `style: StyleObject`
177 - The standard React style object used to style a component with inline styles
178- `className: string`
179 - The standard React className property used to style a component with classes