Skip to main content

@react-router/dev (CLI)

还没翻译译自英文(reactrouter.com)本页 29 段都还没译

React Router CLI

Framework

The React Router CLI comes from the @react-router/dev package. Make sure it is in your package.json devDependencies so it doesn't get deployed to your server.

To get a full list of available commands and flags, run:

npx @react-router/dev -h

react-router build

Builds your app for production with Vite. This command will set process.env.NODE_ENV to production and minify the output for deployment.

react-router build
FlagDescriptionTypeDefault
--assetsInlineLimitStatic asset base64 inline threshold in bytesnumber4096
--clearScreenAllow/disable clear screen when loggingboolean
--config, -cUse specified config filestring
--emptyOutDirForce empty outDir when it's outside of rootboolean
--logLevel, -lUse specified log level"info" | "warn" | "error" | "silent" | string
--minifyEnable/disable minification, or specify minifier to useboolean | "terser" | "esbuild""esbuild"
--mode, -mSet env modestring
--profileStart built-in Node.js inspector
--sourcemapClientOutput source maps for client buildboolean | "inline" | "hidden"false
--sourcemapServerOutput source maps for server buildboolean | "inline" | "hidden"false

react-router dev

Runs your app in development mode with HMR and Hot Data Revalidation (HDR), powered by Vite.

react-router dev

Info

What is "Hot Data Revalidation"?

Like HMR, HDR is a way of hot updating your app without needing to refresh the page. That way you can keep your app state as your edits are applied in your app. HMR handles client-side code updates like when you change the components, markup, or styles in your app. Likewise, HDR handles server-side code updates.

That means any time you make a change to the current page (or any code that your current page depends on), React Router will re-fetch data from your loaders. That way your app is always up to date with the latest code changes, client-side or server-side.

FlagDescriptionTypeDefault
--clearScreenAllow/disable clear screen when loggingboolean
--config, -cUse specified config filestring
--corsEnable CORSboolean
--forceForce the optimizer to ignore the cache and re-bundleboolean
--hostSpecify hostnamestring
--logLevel, -lUse specified log level"info" | "warn" | "error" | "silent" | string
--mode, -mSet env modestring
--openOpen browser on startupboolean | string
--portSpecify portnumber
--profileStart built-in Node.js inspector
--strictPortExit if specified port is already in useboolean

Reverse proxies

The built-in react-router dev and vite preview servers provided by the reactRouter() Vite plugin automatically use X-Forwarded-Proto when constructing request.url. This preserves the browser-facing protocol when a reverse proxy terminates HTTPS and forwards requests over HTTP, allowing same-origin action submissions to pass origin validation. No React Router configuration is required.

The first header value is used if it is http or https (case-insensitive, with surrounding whitespace and an optional trailing : ignored). Missing or invalid values fall back to the connection's protocol. The URL host and port still come from Host, not X-Forwarded-Host or the standard Forwarded header. Preserve the browser-facing host and port in Host and configure Vite's server.allowedHosts or preview.allowedHosts as needed.

Warning

Dev and preview servers are not production servers and should not be publicly accessible. Configure your reverse proxy to overwrite client-supplied X-Forwarded-Proto headers.

react-router reveal

React Router handles the entry points of your application by default.

If you want to have control over these entry points, you can run npx react-router reveal to generate the entry.client.tsx and entry.server.tsx files in your app directory. When these files are present, React Router will use them instead of the defaults.

npx react-router reveal
FlagDescriptionTypeDefault
--config, -cUse specified config filestring
--mode, -mSet env modestring
--no-typescriptGenerate plain JavaScript filesbooleanfalse
--typescriptGenerate TypeScript filesbooleantrue

react-router routes

Prints the routes in your app to the terminal.

react-router routes

Your route tree will be in a JSX format by default. You can also use the --json flag to get the routes in a JSON format.

react-router routes --json
FlagDescriptionTypeDefault
--config, -cUse specified config filestring
--jsonOutput routes in JSON formatbooleanfalse
--mode, -mSet env modestring

react-router typegen

Generates TypeScript types for your routes. This happens automatically during development, but you can manually run it when needed, e.g., to generate types in CI before running tsc. See Type Safety for more information.

react-router typegen
FlagDescriptionTypeDefault
--config, -cUse specified config filestring
--mode, -mSet env modestring
--watchWatch for changesbooleanfalse
Traducción © 2026 fanyi.dev · Original © 2026 React Training LLC, Remix Software Inc., Shopify Inc. (MIT)