如何在 Angular 6 中的单个项目下的多个应用程序之间导航 [英] how to navigate between multiple applications under single project in Angular 6

查看:26
本文介绍了如何在 Angular 6 中的单个项目下的多个应用程序之间导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Angular 6 中的单个项目下创建了多个应用程序,如中所述Angular 6 文章中单个项目下的多个应用程序.

I created multiple applications under single project in Angular 6 as described in Multiple application under single project in Angular 6 article.

如何在我的单个 Angular 项目中的这些应用程序之间导航?

How can I navigate between these applications inside my single angular project?

我尝试了 window.location = "path/to/app2/index.html"; 但它返回给我的错误是路径不正确.

I tried window.location = "path/to/app2/index.html"; but it returns to me error that path is incorrect.

推荐答案

我认为您误解了支持多个应用程序的 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 库集的通常相似的应用程序.在这种情况下,优点是您可以在项目级别安装库一次,而不必在每个应用程序中安装它们.有关如何完成此操作的示例,请参阅 https://yakovfain.com/2017/04/06/angular-cli-multiple-apps-in-the-same-project.

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.

这篇关于如何在 Angular 6 中的单个项目下的多个应用程序之间导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆