# Conflicts: # aio/content/cli/index.md # aio/content/guide/accessibility.md # aio/content/guide/ajs-quick-reference.md # aio/content/guide/angular-compiler-options.md # aio/content/guide/animations.md # aio/content/guide/aot-compiler.md # aio/content/guide/architecture-components.md # aio/content/guide/architecture-modules.md # aio/content/guide/architecture-next-steps.md # aio/content/guide/architecture-services.md # aio/content/guide/attribute-directives.md # aio/content/guide/bootstrapping.md # aio/content/guide/browser-support.md # aio/content/guide/cli-builder.md # aio/content/guide/comparing-observables.md # aio/content/guide/component-styles.md # aio/content/guide/creating-libraries.md # aio/content/guide/dependency-injection-in-action.md # aio/content/guide/dependency-injection-navtree.md # aio/content/guide/dependency-injection-providers.md # aio/content/guide/dependency-injection.md # aio/content/guide/deployment.md # aio/content/guide/deprecations.md # aio/content/guide/displaying-data.md # aio/content/guide/dynamic-component-loader.md # aio/content/guide/elements.md # aio/content/guide/file-structure.md # aio/content/guide/glossary.md # aio/content/guide/http.md # aio/content/guide/i18n.md # aio/content/guide/ivy-compatibility.md # aio/content/guide/language-service.md # aio/content/guide/lifecycle-hooks.md # aio/content/guide/module-types.md # aio/content/guide/ngmodule-faq.md # aio/content/guide/ngmodule-vs-jsmodule.md # aio/content/guide/ngmodules.md # aio/content/guide/observables-in-angular.md # aio/content/guide/pipes.md # aio/content/guide/providers.md # aio/content/guide/releases.md # aio/content/guide/route-animations.md # aio/content/guide/router-tutorial.md # aio/content/guide/router.md # aio/content/guide/rx-library.md # aio/content/guide/schematics-authoring.md # aio/content/guide/schematics-for-libraries.md # aio/content/guide/service-worker-config.md # aio/content/guide/service-worker-getting-started.md # aio/content/guide/structural-directives.md # aio/content/guide/styleguide.md # aio/content/guide/template-syntax.md # aio/content/guide/template-typecheck.md # aio/content/guide/testing.md # aio/content/guide/typescript-configuration.md # aio/content/guide/upgrade-setup.md # aio/content/guide/user-input.md # aio/content/guide/using-libraries.md # aio/content/guide/web-worker.md # aio/content/guide/workspace-config.md # aio/content/marketing/docs.md # aio/content/marketing/events.html # aio/content/navigation.json # aio/content/start/index.md # aio/content/start/start-data.md # aio/content/start/start-deployment.md # aio/content/tutorial/toh-pt2.md # aio/content/tutorial/toh-pt4.md # aio/package.json # aio/src/app/app.component.ts # aio/src/app/layout/footer/footer.component.html # aio/src/app/shared/custom-icon-registry.ts # aio/src/environments/environment.stable.ts # aio/tools/stackblitz-builder/builder.js # aio/tools/transforms/angular-content-package/index.js # aio/tools/transforms/templates/api/lib/memberHelpers.html # aio/yarn.lock # integration/ng_elements/e2e/app.e2e-spec.ts # integration/ng_elements/src/app.ts # packages/common/src/pipes/date_pipe.ts # packages/core/src/metadata/directives.ts # packages/core/src/metadata/ng_module.ts # packages/core/src/render/api.ts # packages/forms/src/directives/ng_model.ts # packages/forms/src/form_builder.ts # packages/forms/src/model.ts # packages/platform-browser/src/browser.ts # packages/router/src/config.ts # packages/router/src/directives/router_link.ts # packages/router/src/directives/router_link_active.ts # packages/router/src/events.ts # packages/router/src/router.ts # packages/router/src/router_module.ts # packages/router/src/router_state.ts
3.6 KiB
App shell
应用外壳
App shell is a way to render a portion of your application via a route at build time. It can improve the user experience by quickly launching a static rendered page (a skeleton common to all pages) while the browser downloads the full client version and switches to it automatically after the code loads.
应用外壳是一种在构建期间借助路由渲染部分应用的方法。它可以通过快速启动一个静态渲染页面(所有页面的公共骨架)来改善用户体验。与此同时,浏览器会下载完整的客户端版本,并在代码加载后自动切换到完整版。
This gives users a meaningful first paint of your application that appears quickly because the browser can simply render the HTML and CSS without the need to initialize any JavaScript.
这能让用户快速看到应用中第一个有意义的画面,因为浏览器可以很简单地渲染出 HTML 和 CSS,而无需初始化任何 JavaScript。
Learn more in The App Shell Model.
欲知详情,参阅应用外壳模型。
Step 1: Prepare the application
第 1 步:准备本应用
You can do this with the following CLI command:
可以用下列 CLI 命令来执行本操作:
ng new my-app --routingFor an existing application, you have to manually add the RouterModule
and defining a <router-outlet>
within your application.
对于既有应用,你必须手动添加 RouterModule
并在应用中定义 <router-outlet>
。
Step 2: Create the app shell
第 2 步:创建应用外壳
Use the CLI to automatically create the app shell.
使用 CLI 自动创建一个应用外壳。
ng generate app-shell-
client-project
takes the name of your client application.client-project
是你这个客户端应用的名字。
After running this command you will notice that the angular.json
configuration file has been updated to add two new targets, with a few other changes.
执行完这个命令,你会发现 angular.json
配置文件中已经增加了两个新目标,并做了一些其它更改。
Step 3: Verify the app is built with the shell content
第 3 步:验证该应用是使用应用外壳的内容构建的
Use the CLI to build the app-shell
target.
使用 CLI 构建目标 app-shell
。
Or to use the production configuration.
或使用产品环境配置。
ng run my-app:app-shell:productionTo verify the build output, open dist/my-app/index.html
. Look for default text app-shell works!
to show that the app shell route was rendered as part of the output.
要验证构建的输出,请打开 dist/my-app/index.html
。寻找默认的文本 app-shell works!
就可以验证这个应用外壳路由确实是作为输出的一部分渲染出来的。