【问题标题】:How to start Angular2 app under a sub forlder如何在子文件夹下启动 Angular 2 应用程序
【发布时间】:2016-06-19 13:29:21
【问题描述】:

按照 Angular2 示例,我创建了我的第一个应用程序 在我的项目文件夹下。我可以运行:“npm start”以使应用程序运行 例如我可以从http://localhost:3000访问应用程序

我有一个新需求,我需要在上下文路径下运行应用程序,这意味着我需要通过http://localhost:3000/myapp访问应用程序

问题是如何在子文件夹路径中部署或运行​​ Angular2 应用程序? 尝试添加 index.html 文件。但是,Angular 似乎无法解析找到模板 URL 和资源 JS 和 TS 文件的路径。

谁能帮助确保我可以在上下文路径“myapp”下运行应用程序?

【问题讨论】:

    标签: node.js angular npm


    【解决方案1】:

    index.html添加base标签:

    <base href="/myapp">
    

    或在您的引导文件 (main.js) 中

    import { provide } from '@angular/core';
    import { APP_BASE_HREF } from '@angular/common';
    
    bootstrap(AppComponent, [
      provide(APP_BASE_HREF, {useValue: '/myapp'}),
    ]);
    

    【讨论】:

      猜你喜欢
      • 2016-10-31
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      • 2017-07-23
      相关资源
      最近更新 更多