使用react-hot-reload和react-router-config

时间:2018-01-11 01:29:00

标签: arrays reactjs react-router-v4 react-hot-loader

当使用renderRoutes(),react-router-config(反应路由器)的配置示例时,rect-hot-reload停止工作,只需在每次更改时重置浏览器。例如,热重新加载仍适用于我的导航组件,但不适用于我的路由组件(主页,功能)。我该如何解决?我正在使用react-hot-reload v4,但v3也是如此。

app.js

render(
  <BrowserRouter>
      <Scenes />
  </BrowserRouter>,
  document.getElementById('app')
)

Scenes.jsx

const Scenes = () => (
  <div id="sceneContainer">
    <Navigation />
    {renderRoutes(routes)}
  </div>
)

export default hot(module)(Scenes)(url)

路线

const routes = [
  {
    component: RouteComponents,
    routes: [
      {
        path: '/',
        component: Home,
        key: 'home',
        exact: true
      },
      {
        path: '/feature',
        component: Feature,
        key: 'feature'
      },
    ],
  },
]

export default routes(url)

RouteComponents

const RouteComponents = (props: Props) => (
  <div id="routeContainer">{renderRoutes(props.route.routes)}</div>
)

export default RouteComponents

0 个答案:

没有答案