iframe引导期间的角度应用路由

时间:2018-06-28 07:05:24

标签: html angular angular-ui-router

我有一个在iframe中运行的角度应用程序。 html看起来像这样。

<html>
  <body>
    <iframe src="http://localhost:9999?screen=two"></iframe>
  </body>
</html>

在提供的路径中,我添加了一个查询参数“ screen”。共有三个视图,路由显示如下。

const routes: Routes = [
  { path: 'one', component: OneComponent },
  { path: 'two', component: TwoComponent },
  { path: '', component: AppComponent }
];

在angular应用程序中,我已解决了要在ngOnInit()的{​​{1}}中显示的组件

app.component.ts

问题是,iframe始终显示OneComponent,直到更改查询参数后重新打开选项卡。 我的问题是:

  1. 为什么会这样?
  2. 有没有一种方法可以更改屏幕 仅更改查询参数并重新加载后,而不是 重新打开标签页?

1 个答案:

答案 0 :(得分:0)

我不确定原因为何,但是有一个修复程序可以在每次查询参数更改时自动刷新iframe

<script>
    var _theframe = document.getElementById("theframe");
    theframe.contentWindow.location.href = theframe.src;
</script>