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,

相关内容

热门资讯

关于!德扑圈透视挂,德扑之星透... 关于!德扑圈透视挂,德扑之星透视脚本插件(果然是有辅助)AI 是一款可以让一直输的玩家修复黑科技更新...
一分钟了解!!wepoker有... 一分钟了解!!wepoker有没有挂,WPK能不能开挂插件(从前是有辅助器)主打本地运行的 AI 黑...
分享开挂内幕!wepoker祈... 分享开挂内幕!wepoker祈福有用吗,微扑克可以开挂吗神器(一直是有辅助挂)主打本地运行的 AI ...
一分钟揭秘!!wpk辅助购买,... 一分钟揭秘!!wpk辅助购买,德扑之星到底有挂吗下载(真是真的有透视)AI 是一款可以让一直输的玩家...
揭秘一下!wepoker私人局... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...
避坑细节!wepoker高级辅... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成wepoker高级辅助解析、 AI ...
玩家必备科普!wpk透视辅助下... 玩家必备科普!wpk透视辅助下载,微扑克到底有挂吗助手(真是是真的有辅助)主打本地运行的 AI 黑科...
实测教程!wepoker辅助脚... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...
分享一款!wepoker有插件... AI 黑科技赛道又上新,这款智能处理工具堪称效率开挂,专门面向短视频创作者打造。它打通脚本撰写、AI...
一分钟了解!德普之星透视辅助软... 一分钟了解!德普之星透视辅助软件是真的吗,微扑克真的有透视吗下载(从前存在有透视)AI 智能体黑科技...