【问题标题】:Run angular7 application from legacy web application从旧版 Web 应用程序运行 angular7 应用程序
【发布时间】:2019-10-31 08:46:13
【问题描述】:

我已经构建了一个新的 Angular7 应用程序,并且本地 Angular 应用程序运行良好。 现在我需要从基于 Java/JSP 构建的现有遗留 Web 应用程序启动我的 Angular 应用程序。 在现有的遗留应用程序中,我有一个 URL。单击该 URL 后,应打开 Angular 应用程序。

但是每当我点击 URL 时,似乎路由没有正确地发生在 Angular 应用程序中。

本地 Angular 应用程序正在成功运行 - http://localhost:4200/alerts;alerttype=renewals;cor=411119

到目前为止我所做的, 我已将 angular dist 文件夹复制到旧版应用程序的 webcontent 文件夹中,并按如下方式运行应用程序

http://localhost:9086/customer/eWeb/AlertApp/alerts;alerttype=renewals;cor=411119

app.routing.module.ts

    const routes: Routes = [
    { path: 'alerts', component: AlertsComponent },
    { path: 'customer/eWeb/AlertApp/alerts', component: AlertsComponent 
     },
    ];

谁能帮助并告诉如何从遗留应用程序启动角度应用程序?需要配置什么所有路由?

提前致谢。

【问题讨论】:

    标签: angular angular-ui-router angular7-router


    【解决方案1】:

    一旦你构建了你的 Angular 应用程序,你会得到一些 js 和 css 文件(取决于你的代码,模式细节here

    只需在服务器上捆绑和移动这些文件,然后在 JSP 页面上调用主文件 (bundle.js)。

    在此之前,别忘了在 index.html 中设置基本路径

    【讨论】:

    • 所以在我的例子中,index.html 中的基本路径是 你想添加别的东西吗?我也没有在构建后看到主 bundle.js 文件
    【解决方案2】:

    更新您的服务器端 url 配置(SpringMVC 或 SpringBoot 配置或 Servlet web.xml)以返回您的父 jsp。

    http://localhost:9086/customer/eWeb/AlertApp --> app.jsp

    在 app.jsp 中,只包含 css + 捆绑的 js 文件(类似于你的 angular index.html)

    <body>
     <div app> </div>
     <script type="text/javascript" src="runtime.js"></script><script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="scripts.js"></script><script type="text/javascript" src="main.js"></script>
    </body>
    

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多