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,

相关内容

热门资讯

了解辅助!逍遥卡五星辅助,新祥... 了解辅助!逍遥卡五星辅助,新祥心挂机(太坑了辅助开挂脚本);逍遥卡五星辅助最新软件透视开挂直接下载安...
科技透视"wepok... 科技透视"wepoker辅助器教程"开挂(透视)辅助平台(推荐几款新版AA德州教程)科技透视"wep...
传授开挂!四川辅助工具,小程序... 传授开挂!四川辅助工具,小程序牵手跑得有开挂吗(太夸张了辅助开挂脚本);1.小程序牵手跑得有开挂吗 ...
通报透视"wepok... 通报透视"wepoker真的有挂透视辅助吗"开挂(透视)辅助神器(最新技巧揭秘攻略)【福星临门,好运...
教会辅助!蜀山四川破解版安卓版... 教会辅助!蜀山四川破解版安卓版,逸趣鄱阳翻精辅助(太实锤了辅助开挂下载),蜀山四川破解版安卓版是用手...
正版透视"wepok... 正版透视"wepoker德州透视软件是真的吗"开挂(透视)辅助平台(科技介绍攻略方法)正版透视"we...
科技辅助!腾旭欢乐全集辅助,创... 科技辅助!腾旭欢乐全集辅助,创思维激k看底牌辅助(太离谱了开挂辅助工具);大家肯定在之前创思维激k看...
通报透视"wepok... 通报透视"wepoker透视教程"开挂(透视)辅助平台(玩家必看科普详细教程)通报透视"wepoke...
传授辅助!微乐斗地主有挂吗,小... 传授辅助!微乐斗地主有挂吗,小程序牵手跑得辅助(太夸张了开挂辅助安装);1、不需要AI权限,帮助你快...
细节透视"wepok... 细节透视"wepoker是不是有辅助"开挂(透视)辅助软件(玩家必看秘籍解密教程)细节透视"wepo...