【问题标题】:how to make route to wait till feature module is loaded in angular如何使路线等到功能模块以角度加载
【发布时间】:2018-06-14 11:04:51
【问题描述】:

我有一个 Angular 应用程序,它具有不同的延迟加载模块。 app.html 的结构是

<mat-toolbar></mat-toolbar>
<router-outlet></router-outlet>
<app-footer></app-footer>

在开始路由页面时,页脚会出现在工具栏下方的顶部一段时间,直到延迟加载的模块完成加载。 这也在 SEO 中影响它。例如在谷歌 PageSpeed Insights (https://developers.google.com/speed/pagespeed/insights/) 上, 页面是空的。我认为我不需要使用角度路由解析器,因为这里的重点是等待模块加载 不要等待数据到达。我怎样才能让路由等到模块加载完毕。

【问题讨论】:

  • 网站正在加载中
  • @DeepanshParmani 网站正在加载是什么意思?
  • 对不起,我的意思是网站没有加载
  • 这个链接怎么样:ahaduproperty.com
  • 是的,它的工作原理

标签: angular


【解决方案1】:

将下面的代码放在index.html 中解决了google page speed insight上空白页的问题:

<script>
if (window.document.documentMode) {
  // polyfill IE11 in a blocking way
  var s = document.createElement('script');
  s.src = 'generated/ie-polyfills.min.js';
  document.head.appendChild(s);
} else if (!Object.assign) {
  // polyfill other non-evergreen browsers in a blocking way
  var polyfillUrl = "https://cdn.polyfill.io/v2/polyfill.min.js?features=default,Array.prototype.find&flags=gated&unknown=polyfill";
  // send a blocking XHR to fetch the polyfill
  // then append it to the document so that its eval-ed synchronously
  // this is required because the method used for IE is not reliable with other non-evergreen browsers
  var xhr = new XMLHttpRequest();
  xhr.addEventListener("load", function() {
    var s = document.createElement('script');
    s.type = 'text/javascript';
    var code = this.responseText;
    s.appendChild(document.createTextNode(code));
    document.head.appendChild(s);
  });
  xhr.open("GET", polyfillUrl, false);
  xhr.send();
}

根据this的回答。

【讨论】:

    猜你喜欢
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多