Skip to main content
Version: Next

React Router Integration with Platformatic Watt

Package​

@platformatic/react-router

This capability runs a React Router (formerly Remix) application as a Platformatic Runtime application with no modifications. Use it for React Router framework mode / React Router Start apps, not for plain client-side react-router-dom routing inside another framework.

Platformatic React Router supports React Router 7 and 8. React Router v7 is the continuation of Remix. For classic Remix v1/v2 projects (remix.config.js), use remix.md and @platformatic/remix instead.

Detection Files​

  • react-router.config.ts
  • react-router.config.js

Backed by @react-router/dev in dependencies. React Router apps are Vite-based, so they also have a vite.config.{ts,js}. Detect React Router from react-router.config.* first; fall back to @platformatic/vite only when no react-router.config.* is present.

watt.json Configuration​

Platformatic manages the development, build, and production lifecycle for you, so you do not need an application.commands block. A standalone React Router app used as the Watt entrypoint:

{
"module": "@platformatic/react-router",
"runtime": {
"logger": {
"level": "{PLT_SERVER_LOGGER_LEVEL}"
},
"server": {
"hostname": "{PLT_SERVER_HOSTNAME}",
"port": "{PORT}"
}
}
}

When the app runs behind a Platformatic Gateway under a path prefix, add application.basePath:

{
"module": "@platformatic/react-router",
"application": {
"basePath": "/frontend"
}
}

Installation​

npm install wattpm@^3.74.0 @platformatic/react-router@^3.74.0

Key Considerations​

No commands needed​

Platformatic detects React Router and runs dev, build, and production itself. Only add application.commands if you need a custom command pipeline. The default production server is started by Platformatic from the SSR build output.

Running behind a Gateway​

When the entrypoint is a Platformatic Gateway, the app must honor the base path. Update react-router.config.ts:

import type { Config } from '@react-router/dev/config'
import { getBasePath } from '@platformatic/globals'

export default {
basename: getBasePath({ throwOnMissing: false }) ?? '/',
ssr: true
} satisfies Config

And vite.config.ts:

import { getBasePath } from '@platformatic/globals'
import { reactRouter } from '@react-router/dev/vite'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
base: getBasePath({ throwOnMissing: false }) ?? '/',
plugins: [reactRouter(), tsconfigPaths()]
})

Mesh networking​

Allow other Watt applications to reach the dev server by adding .plt.local to the Vite allowed hosts in vite.config.ts:

export default defineConfig({
plugins: [reactRouter()],
server: {
allowedHosts: ['.plt.local']
}
})

Custom SSR entrypoint​

To provide a custom server entrypoint, point the Vite SSR build at app/server.ts and export an entrypoint from that file. The Vite config below works with React Router 7 and 8. In React Router 8 the Vite Environment API is always enabled, so build.rollupOptions.input gated on isSsrBuild is ignored unless you also set environments.ssr.build.rollupOptions.input.

// vite.config.ts
export default defineConfig(({ isSsrBuild }) => ({
base: getBasePath({ throwOnMissing: false }) ?? '/',
// React Router 7
build: {
rollupOptions: isSsrBuild ? { input: './app/server.ts' } : undefined
},
// React Router 8
environments: {
ssr: {
build: {
rollupOptions: {
input: './app/server.ts'
}
}
}
},
plugins: [reactRouter(), tsconfigPaths()]
}))
// app/server.ts
export const entrypoint = import('virtual:react-router/server-build')

Migrating to React Router 8​

See the official React Router upgrade guide. React Router 8 requires Node.js 22.22+, React 19.2.7+, and Vite 7+. The react-router-dom package has been removed; import from react-router instead (use react-router/dom only for RouterProvider or HydratedRouter). If a custom server still sets its SSR input only via isSsrBuild, update vite.config.ts as shown above or the production command (for example node build/server/index.js) will not start a server.

Port is managed by Platformatic​

In development and production Platformatic chooses the HTTP port and overrides any user or application setting. Do not hardcode a port in the app.

Environment Variables​

PORT=3000
PLT_SERVER_HOSTNAME=0.0.0.0
PLT_SERVER_LOGGER_LEVEL=info

HTTPS​

When React Router is the Watt entrypoint, configure HTTPS in the runtime server.https object. This fragment belongs at the runtime root; wrap it in runtime for a standalone capability:

{
"server": {
"https": {
"key": { "path": "./certs/server.key" },
"cert": { "path": "./certs/server.crt" }
}
}
}

TypeScript​

React Router's build pipeline handles TypeScript and JSX. Native Node.js type stripping can load supported server-side TypeScript but does not replace the framework build or type checking.

Common Issues​

Detected as plain Vite​

A React Router app has a vite.config.*. If the skill picks @platformatic/vite, check for react-router.config.* and switch to @platformatic/react-router.

Routes 404 behind a Gateway​

The base path is not wired up. Set basename in react-router.config.ts and base in vite.config.ts with getBasePath() from @platformatic/globals.

Dev server unreachable from other applications​

Add '.plt.local' to server.allowedHosts in vite.config.ts.

Production custom server does not start after upgrading to React Router 8​

The Vite Environment API is always on in v8, so a custom SSR input set only with build.rollupOptions.input and isSsrBuild is ignored. Move the input to environments.ssr.build.rollupOptions.input as in Custom SSR entrypoint.