angular - 通过 fileReplacements 在 Angular 中处理静态页面
问题描述
我正在寻找以下问题的解决方案。
我的应用程序将由两部分组成:
- SPA APP - Angular App - 标准配置/模式,
app/src/...index.html
-> 从那个地方是引导组件。
带有静态 html 和多个登录页面的文件夹
Folder: LandingPage1/index.html (and another pages) LandingPage2/index.html (and another pages) LandingPage3/index.html (and another pages) index.html
问题是:
从后端,从第一个请求中,我得到了有关 LandingPage 名称的信息 - fe LandingPage1。我想从
Folder:
LandingPage1/index.html (and another pages)
LandingPage2/index.html (and another pages)
LandingPage3/index.html (and another pages)
index.html <- here - <app-root>
并且依赖于请求响应可以通过 LandingPage 路由访问同名文件夹。
在 React 中——我们有专门的解决方案——而且非常简单:
https://create-react-app.dev/docs/using-the-public-folder/
我们可以在角度上做同样的事情吗?现在我正在尝试:
-> 将 LandingPages 文件夹放到资产中 -> 并在 angular.json 中通过 fileReplacments 处理它(index.html)(但是 css 呢?)
解决方案
首先,您应该使用自己的逻辑和后端 plusAngular-router
来处理路由(阅读文档)
创建组件和路由以在模板中呈现 HTML 文件后,您可以使用[innerHtml]
. 请记住,文件扩展名不会打印在 URL 中,因为它被注入到 Angular 模板中,因此默认情况下它看起来example.com/LandingPage1
像example.com/LandingPage1/index.html
最佳做法是将 html 文件存储在 /src/views 文件夹中
import { Component } from '@angular/core';
var template = require("./html1.html");
declare var require: {
(path: string): any;
<T>(path: string): T;
(paths: string[], callback: (...modules: any[]) => void): void;
ensure: (paths: string[], callback: (require: <T>(path: string) => T) =>
void) => void;
};
@Component({
selector: 'my-app',
template: `<div [innerHtml]="html1">`
})
export class AppComponent {
html1:string = template;
}
(但是 CSS 呢?)
之后,您可以在此处导入您的全局 CSS:
推荐阅读
- postgresql - PostgreSQL - 如何使用四个表进行连接查询?
- c# - C#从字节数组中获取第一个字节索引
- excel - 复制模板并填写另一个工作表中的值
- html - 当我设置溢出时,工具提示的悬停不起作用:为其父级隐藏
- typescript - React-Native - 如何制作交互式图表
- angular - Angular & ngx-socket-io & NestJs - 客户端应用程序未接收服务器事件发射
- terminology - 我不确定 3D 图形编程中的“卷积”是什么意思
- websocket - 如何通过 websockets 在本地 RSK 节点上订阅“newBlockHeaders”?
- python - 令人惊讶的智能 python 导入行为:幕后发生了什么?
- android - 将 profileimage 节点添加到 firebase 实时数据库