【问题标题】:Server render cannot get the nested route string服务器渲染无法获取嵌套路由字符串
【发布时间】:2019-04-02 09:03:39
【问题描述】:

当我访问/m/song时,htmlstring只包含Layouts组件

htmlstring = renderToString(
    <Provider store={store}>
        <StaticRouter location={ctx.url} context={context}>
            {renderRoutes(routesConfig)}
        </StaticRouter>
    </Provider>
);


const routesConfig = [{
    component: Layouts,
    routes:[{path: '/m/song', componentName: 'Song', component: Song}]
    …

htmlstring 应该包含 Layouts 和 Song 组件。

【问题讨论】:

    标签: reactjs react-router react-router-v4 server-rendering


    【解决方案1】:

    您是否在“布局”组件的渲染中包含以下内容? {renderRoutes(routesConfig.routes)}

    根据文档, npmjs.com/package/react-router-config,没有这条线,子路线(在你的情况下是“歌曲”)将不会呈现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-12
      • 2011-08-06
      • 2017-01-22
      • 1970-01-01
      • 2017-06-07
      • 2017-11-15
      相关资源
      最近更新 更多