且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Angular 6中的单个项目下的多个应用程序之间导航

更新时间:2023-11-09 15:11:52

我认为您误解了支持多个应用程序的Angular项目的目的.

I think that you have misunderstood the purpose of an Angular project supporting multiple applications.

我认为基本上有两种情况可以支持此功能:

There are basically two scenarios that I believe that this feature is meant to support:

  1. 一个库项目,以及一个用于执行它的示例应用程序.

  1. A library project, and a sample application that is used to exercise it.

使用相同或相似NPM库集的多个通常相似的应用程序.在这种情况下,优点是您可以在项目级别安装一次库,而不必在每个应用程序中安装它们.有关此操作的示例,请参见

Multiple, usually similar applications that use the same or similar sets of NPM libraries. In this case, the advantage is that you can install the libraries at the project level once, instead of having to install them in each application. For an example of how this is done, see https://yakovfain.com/2017/04/06/angular-cli-multiple-apps-in-the-same-project.

这两个用例都不涉及同时运行两个Angular应用程序并在它们之间进行切换.据我所知,这不受支持.

Neither of these use-cases involves running two Angular applications at the same time, and switching between them. As far as I know, this is not supported.

您可能想要做的是将两个应用程序中的组件组合到一个应用程序中,而每个先前的应用程序都在其自己的模块中.然后,您可以使这些模块中的每个模块延迟加载,并使用应用程序的***路由器在两个模块之间进行切换.

What you may want to do instead is to combine the components from both applications into one application, with each former application in it's own module. You can then make each of these modules lazy-loaded, and use the application's top-level router to switch between the two modules.