LiveReload
On this page

<LiveReload />

此组件将你的应用连接到 Remix 资源服务器,并在开发过程中文件发生变化时自动重新加载页面。在生产环境中,它会渲染 null,因此你可以始终在根路由中安全地渲染它。

¥This component connects your app to the Remix asset server and automatically reloads the page when files change in development. In production, it renders null, so you can safely render it always in your root route.

import { LiveReload } from "@remix-run/react";

export default function Root() {
  return (
    <html>
      <head />
      <body>
        <LiveReload />
      </body>
    </html>
  );
}

属性

¥Props

origin

为 Live Reload 协议指定自定义源。提供的 URL 应该使用 http 协议,该协议将在内部升级到 ws 协议。这在 Remix 开发服务器前使用反向代理时非常有用。默认值为 REMIX_DEV_ORIGIN 环境变量,或者仅在未设置 REMIX_DEV_ORIGIN 时才为 window.location.origin

¥Specify a custom origin for the Live Reload protocol. The url provided should use the http protocol, that will be upgraded to ws protocol internally. This is useful when using a reverse proxy in front of the Remix dev server. The default value is the REMIX_DEV_ORIGIN environment variable, or window.location.origin only if REMIX_DEV_ORIGIN is not set.

port

为 Live Reload 协议指定自定义端口。默认值是从 REMIX_DEV_ORIGIN 环境变量派生的端口,或者仅在未设置 REMIX_DEV_ORIGIN 时才使用 8002

¥Specify a custom port for the Live Reload protocol. The default value is the port derived from REMIX_DEV_ORIGIN environment variable, or 8002 only if REMIX_DEV_ORIGIN is not set.

timeoutMs

timeoutMs 属性允许为 Live Reload 协议指定自定义超时时间,以毫秒为单位。这是 Web Socket 连接丢失后尝试重新连接的延迟时间。默认值为 1000

¥The timeoutMs prop allows specifying a custom timeout for the Live Reload protocol, in milliseconds. This is the delay before trying to reconnect if the Web Socket connection is lost. The default value is 1000.

Remix v2.17 中文网 - 粤ICP备13048890号