【问题标题】:kadira:flow-router route executes before the DOM is renderedkadira:flow-router 路由在 DOM 渲染之前执行
【发布时间】:2015-12-15 13:37:59
【问题描述】:

我正在尝试使用流路由器在流星中做出反应。路由定义如下:

  FlowRouter.route('/',
     {
        action(){
           const containerElement = document.getElementById("react-root");
           if (containerElement) {
              const app = React.createElement("<App/>");
              ReactDOM.render(app, containerElement);
           } else {
              console.log("no element react-root found");
           }
        }
     })

HTML 非常基础:

    <head>
        <title>Todo List</title>
    </head>

    <body>
        <div id="react-root">react-root</div>
    </body>

当我启动流星并导航到 localhost:3000 时,我在页面上收到 react-root,在控制台中收到消息 no element react-root found

我试图将路由定义包装在 Meteor.startup( 中,但随后我收到一个错误,即路由 / 未定义。

【问题讨论】:

    标签: meteor


    【解决方案1】:

    根据来自 arunoda 的this comment

    现在流路由器不等待 DOM。我们在布局层做。

    所以在您选择使用React LayoutBlaze Layout 之前,您可以像这样包装您的代码以仅在加载DOM 时触发它:

    FlowRouter.route('/',
     {
        action(){
         $(function () {
           const containerElement = document.getElementById("react-root");
           if (containerElement) {
              const app = React.createElement("<App/>");
              ReactDOM.render(app, containerElement);
           } else {
              console.log("no element react-root found");
           }
         });
        }
     })
    

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-28
      • 2021-08-10
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      相关资源
      最近更新 更多