创新互联Angular教程:Angular应用外壳
应用外壳
应用外壳是一种在构建期间借助路由渲染部分应用的方法。它可以通过快速启动一个静态渲染页面(所有页面的公共骨架)来改善用户体验。与此同时,浏览器会下载完整的客户端版本,并在代码加载后自动切换到完整版。

成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都做网站、网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的瓦房店网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
这能让用户快速看到应用中第一个有意义的画面,因为浏览器可以渲染出 HTML 和 CSS,而无需初始化任何 JavaScript。
欲知详情,参阅应用外壳模型。
第 1 步:准备本应用
可以用下列 CLI 命令来执行本操作:
ng new my-app --routing对于既有应用,你必须手动添加 RouterModule 并在应用中定义 。
第 2 步:创建应用外壳
使用 CLI 自动创建一个应用外壳。
ng generate app-shell执行完这个命令,你会发现 Angular.json 配置文件中已经增加了两个新目标,并做了一些其它更改。
"server": {
"builder": "@angular-devkit/build-angular:server",
"defaultConfiguration": "production",
"options": {
"outputPath": "dist/my-app/server",
"main": "src/main.server.ts",
"tsConfig": "tsconfig.server.json"
},
"configurations": {
"development": {
"outputHashing": "none",
},
"production": {
"outputHashing": "media",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"sourceMap": false,
"optimization": true
}
}
},
"app-shell": {
"builder": "@angular-devkit/build-angular:app-shell",
"defaultConfiguration": "production",
"options": {
"route": "shell"
},
"configurations": {
"development": {
"browserTarget": "my-app:build:development",
"serverTarget": "my-app:server:development",
},
"production": {
"browserTarget": "my-app:build:production",
"serverTarget": "my-app:server:production"
}
}
}第 3 步:验证该应用是使用应用外壳的内容构建的
使用 CLI 构建目标 app-shell。
ng run my-app:app-shell:development或使用产品环境配置。
ng run my-app:app-shell:production要验证构建输出,请打开 dist/my-app/browser/index.html。寻找默认的文本 app-shell works! 就可以验证这个应用外壳路由确实是作为输出的一部分渲染出来的。
文章题目:创新互联Angular教程:Angular应用外壳
新闻来源:http://www.jxjierui.cn/article/ccciesc.html


咨询
建站咨询
