如何在 angular 2+ 中从一个应用程序路由到另一个应用程序

How to route from one application to another application in angular 2+

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

使用window.location.href='externalurl'

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

您可以 "route" 到另一个应用程序的唯一方法是使用 window.location.href.

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

可能值得考虑将两个 "apps" 作为模块放在单个 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'])

希望对您有所帮助。