如何在角度2+中从一个应用程序路由到另一个应用程序[关闭]

问题描述 投票:-2回答:2

我在角度7中有两个不同的应用程序,我想在它们之间导航。如何通过使用角度路由实现它?

angular angular2-routing
2个回答
0
投票

总之,你不能。 Angular Routing在Angular应用程序中工作,因此两个应用程序都有自己的Angular路由器和路由器配置。

你可以“路由”到另一个应用程序的唯一方法是使用window.location.href

值得注意的是,在执行此操作时,您将卸载现有的Angular应用程序并加载到新的Angular应用程序中(换句话说,将从浏览器中卸载当前应用程序的所有状态,资产和文件),向前和向后导航这两个应用程序之间的关系可能会变得昂贵,因为每次导航到应用程序时都会加载并启动每个应用程序。

可能值得考虑将单个Angular应用程序中的两个“应用程序”作为模块或sub-applications,然后您可以使用延迟加载路由到它们。

例如,您的路由器配置看起来像这样

[
  { path: 'app1', loadChildren: 'path/to/module/for/app1#ModuleName' },
  { path: 'app2', loadChildren: 'path/to/module/for/app2#ModuleName' }
]

然后在您的应用程序中,您可以使用this.router.navigate(['/app1'])

我希望有所帮助。


0
投票

使用window.location.href='externalurl'

© www.soinside.com 2019 - 2024. All rights reserved.