AngularUniversal中动态元标题未在视图页面源中显示
创始人
2024-10-29 21:30:27
0

在 Angular Universal 中,动态元标题使用 MetaService 和 ActivatedRoute 设置。但是,当使用 Angular Universal 启用服务器端渲染时,动态元标题可能无法在视图页面源中显示。要解决此问题,可以使用以下方法:

1.安装 @nguniversal/module-map-ngfactory-loader 包以使用Lazy Loading

npm install @nguniversal/module-map-ngfactory-loader --save

2.修改 webpack.server.config.js 文件

const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader'); const { ROUTES } = require('./static.paths'); const { existsSync } = require('fs'); const { join } = require('path');

....

module.exports = { .... resolve: { modules: [ join(process.cwd(), 'dist'), 'node_modules' ] }, entry: { server: './server.ts' }, target: 'node', output: { path: join(process.cwd(), 'dist', 'server'), filename: '[name].js' }, .... plugins: [ new webpack.ContextReplacementPlugin( /angular(\|/)core/, path.join(__dirname, 'src'), {} ), new webpack.ContextReplacementPlugin( /@angular(\|/)core(\|/)fesm5/, path.join(__dirname, 'src'), {} ), new webpack.ContextReplacementPlugin( /ngx(-|/)(module|directive)/, path.join(__dirname, 'src'), {} ), new webpack.IgnorePlugin(/^vertx$/), new webpack.IgnorePlugin(/^pg-native$/), new webpack.IgnorePlugin(/^buffertools$/), new webpack.IgnorePlugin(/^mysql$/), new webpack.IgnorePlugin(/^pg-query-stream$/) ], externals: [ /node_modules/, function (context, request, callback) { if (request.match(/^(?!.|/).+/)) { callback(null, commonjs ${request}); } else { callback(); } } ] };

3.修改 app.server.module.ts 文件

import { NgModule } from '@angular/core'; import { ServerModule, ServerTransferStateModule } from '@angular/platform-server'; import { ModuleMapLoaderModule } from '@nguniversal/module-map-ngfactory-loader'; import { AppModule } from './app.module'; import { AppComponent } from './app.component';

@NgModule({ imports: [ AppModule,

相关内容

热门资讯

分享一款!wepoker私人局... 分享一款!wepoker私人局透视方法,wepoker黑侠破解,确实有挂(有挂技巧)1. 选牌创建新...
一直以来!wpk模拟器,德普之... 一直以来!wpk模拟器,德普之星透视辅助软件是真的吗,竟然真的有挂(有挂攻略)德普之星透视辅助软件是...
一分钟了解!hhpoker为什... 一分钟了解!hhpoker为什么一直输,hhpoker脚本,竟然有挂(真的有挂)1、任何透视是真的假...
据通报!wepoker私人定制... 据通报!wepoker私人定制透视,德普之星有透视辅助吗,果然存在有挂(有挂辅助)该软件可以轻松地帮...
最新研发!wepoker养号规... 最新研发!wepoker养号规律,德普之星透视辅助,好像是有挂(有挂秘诀)亲,关键说明,透视脚本安卓...
最终!wepoker好友助力码... 最终!wepoker好友助力码,智星德州有脚本吗,本来存在有挂(有挂详细)1、首先打开智星德州有脚本...
出现新变化!德扑之心免费透视,... 出现新变化!德扑之心免费透视,德普之星怎么设置埋牌,其实是有挂(果真有挂)1、德普之星怎么设置埋牌有...
一分钟带你了解!约局吧如何查看... 一分钟带你了解!约局吧如何查看是否有挂,wepoker透视有吗,切实是真的有挂(有挂讲解)1、公共底...
此事引发网友热议!WePOke... 此事引发网友热议!WePOker有没有透视方法,德普之星辅助器,原来真的是有挂(有挂秘诀)1、任何德...
记者揭秘!pokemmo免费脚... 记者揭秘!pokemmo免费脚本,hhpoker辅助软件下载,都是存在有挂(有挂技术)1、玩家可以在...