| title | React Router Devtools General Configuration |
|---|---|
| summary | General configuration covers plugin directory setup, TanStack DevTools integration, and controlling whether client or server parts of React Router Devtools are included in production. |
| description | General Configuration options for the React Router Devtools |
This covers the general configuration options for the React Router Devtools.
type ReactRouterViteConfig = {
client?: Partial<RdtClientConfig>
server?: DevToolsServerConfig
pluginDir?: string
includeInProd?: {
client?: boolean
server?: boolean
devTools?: boolean
}
tanstackConfig?: Omit<Partial<TanStackDevtoolsConfig>, "customTrigger">
tanstackClientBusConfig?: Partial<ClientEventBusConfig>
tanstackViteConfig?: TanStackDevtoolsViteConfig
experimental_codegen?: {
enabled: boolean
}
}The relative path to your plugin directory. If you have a directory for react-router-devtools plugins you can point to it and they will be automatically imported and added to the dev tools.
Example:
import { reactRouterDevTools } from "react-router-devtools";
export default defineConfig({
plugins: [
reactRouterDevTools({
pluginDir: "./plugins"
}),
reactRouter(),
],
});This option is used to set whether parts of the plugin should be included in production builds or not.
By default, all parts are excluded from production builds. You can selectively include different parts:
client: Include the devtools UI in productionserver: Include server-side logging and utilities in productiondevTools: Include TanStack DevTools integration in production
includeInProd?: {
client?: boolean // Default: false
server?: boolean // Default: false
devTools?: boolean // Default: false
}Example:
import { reactRouterDevTools } from "react-router-devtools";
export default defineConfig({
plugins: [
reactRouterDevTools({
includeInProd: {
client: false,
server: true, // Include server logs in production
devTools: false
},
}),
reactRouter(),
],
});You can also control this behavior using environment variables.
Again, you can selectively include different parts:
VITE_INCLUDE_CLIENT_IN_PROD=true: Include the devtools UI in productionVITE_INCLUDE_SERVER_IN_PROD=true: Include server-side logging and utilities in productionVITE_INCLUDE_DEVTOOLS_IN_PROD=true: Include TanStack DevTools integration in production
Example:
# VITE_INCLUDE_CLIENT_IN_PROD=true
VITE_INCLUDE_SERVER_IN_PROD=true # Include server logs in production
VITE_INCLUDE_DEVTOOLS_IN_PROD=falseImportant notes:
- The server part uses chalk which might not work in non-node environments
- If you wish to edit the plugin server config in production, you can set
process.rdt_configto an object with the same shape as the config object and it will be used instead of the default production config ({ silent: true }) - Consider adding authentication/authorization checks before exposing devtools in production
React Router Devtools v6+ integrates with TanStack DevTools, providing enhanced debugging capabilities. You can configure TanStack-specific behavior through these options:
Configure the TanStack DevTools behavior and appearance.
tanstackConfig?: Omit<Partial<TanStackDevtoolsConfig>, "customTrigger">All the options are available here: https://tanstack.com/devtools/latest/docs/configuration
Common options:
import { reactRouterDevTools } from "react-router-devtools";
export default defineConfig({
plugins: [
reactRouterDevTools({
tanstackConfig: {
position: "bottom-right", // Position of the devtools trigger
// Add other TanStack config options as needed
}
}),
reactRouter(),
],
});Configure the TanStack client event bus for advanced use cases.
tanstackClientBusConfig?: Partial<ClientEventBusConfig>This is an advanced option for customizing how TanStack DevTools communicates between client and server. Most users won't need to configure this.
Example:
import { reactRouterDevTools } from "react-router-devtools";
export default defineConfig({
plugins: [
reactRouterDevTools({
tanstackClientBusConfig: {
// Advanced event bus configuration
}
}),
reactRouter(),
],
});Configure the TanStack Vite plugin directly for advanced scenarios.
tanstackViteConfig?: TanStackDevtoolsViteConfigThis allows you to pass configuration directly to the underlying TanStack DevTools Vite plugin.
Example:
import { reactRouterDevTools } from "react-router-devtools";
export default defineConfig({
plugins: [
reactRouterDevTools({
tanstackViteConfig: {
// TanStack Vite plugin configuration
}
}),
reactRouter(),
],
});The experimental_codegen option enables automatic type annotation generation for your React Router route exports. When enabled, the plugin will automatically add type annotations to your route exports (loader, action, default component, etc.) when files are created or modified.
experimental_codegen?: {
enabled: boolean // Default: false
}When you create or edit a route file, the plugin will automatically:
- Add the Route type import from
./+types/{filename} - Add type annotations to exported functions like
loader,action,clientLoader,clientAction,meta,links,headers,ErrorBoundary, andHydrateFallback - Add type annotations to the default exported component
- Add type annotations to
middlewareandclientMiddlewarearray exports
Before (what you write):
export const loader = ({ request }) => {
return { data: "hello" }
}
export const middleware = []
export default function MyRoute({ loaderData }) {
return <div>{loaderData.data}</div>
}After (automatically transformed):
import type { Route } from "./+types/my-route";
export const loader = ({ request }: Route.LoaderArgs) => {
return { data: "hello" }
}
export const middleware: Route.MiddlewareFunction[] = []
export default function MyRoute({ loaderData }: Route.ComponentProps) {
return <div>{loaderData.data}</div>
}To enable this feature, add the experimental_codegen option to your config:
import { reactRouterDevTools } from "react-router-devtools";
export default defineConfig({
plugins: [
reactRouterDevTools({
experimental_codegen: {
enabled: true
}
}),
reactRouter(),
],
});Notes:
- Only functions with parameters will have types added (functions with no parameters are skipped)
- Exports that already have type annotations are skipped
- The type import path follows React Router v7 conventions:
./+types/{filename}
Here's a complete example showing all general configuration options:
import { defineConfig } from 'vite'
import { reactRouter } from '@react-router/dev/vite'
import { reactRouterDevTools, defineRdtConfig } from "react-router-devtools"
const rdtConfig = defineRdtConfig({
// Client configuration
client: {
expansionLevel: 2,
routeBoundaryGradient: "gotham",
},
// Server configuration
server: {
silent: false,
logs: {
loaders: true,
actions: true,
}
},
// Plugin directory
pluginDir: "./plugins",
// Production inclusion
includeInProd: {
client: false,
server: true,
devTools: false,
},
// TanStack DevTools configuration
tanstackConfig: {
position: "bottom-right",
buttonPosition: "bottom-right",
},
// TanStack client bus configuration (advanced)
tanstackClientBusConfig: {
// Custom event bus config if needed
},
// TanStack Vite plugin configuration (advanced)
tanstackViteConfig: {
// Custom Vite plugin config if needed
},
// Experimental codegen for automatic type annotations
experimental_codegen: {
enabled: true
}
})
export default defineConfig({
plugins: [
reactRouterDevTools(rdtConfig),
reactRouter(),
],
})The defineRdtConfig helper provides type safety for your configuration:
import { defineRdtConfig } from "react-router-devtools"
const config = defineRdtConfig({
// Your configuration with full TypeScript support
client: {
expansionLevel: 2,
},
tanstackConfig: {
position: "bottom-right",
}
})
export default configYou can then import and use this configuration in your vite.config.ts:
import { reactRouterDevTools } from "react-router-devtools"
import rdtConfig from "./rdt.config"
export default defineConfig({
plugins: [
reactRouterDevTools(rdtConfig),
reactRouter(),
],
})