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透视挂效果... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成WePoker透视挂效果如何解析、 ...
技术分享,wepoker有透视... 技术分享,wepoker有透视挂吗,菠萝智星德州有挂么绝活儿(一直是有辅助挂)AI 智能体黑科技再上...
切实教程,wepokerplu... 切实教程,wepokerplus德州作弊,智星菠萝德州透视神器法子(往昔真的是有开挂)主打本地运行的...
AI教程,德扑之星的亮点,德扑... 您好,AI教程,德扑之星的亮点,德扑之星透视开挂项目(最初有透视)这款游戏可以开挂的,确实是有挂的,...
玩家必备科普,WePoKer透... 玩家必备科普,WePoKer透视软件怎么用,wpk到底有挂吗要领(起初真的有透视挂)AI 智能体黑科...
玩家必备教程,wepoker发... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...
热门推荐,wepokerplu... 您好:wepokerplus辅助透视教程这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都...
解密关于,wpk破解器,菠萝智... 您好:wpk破解器这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别...
一分钟快速了解,手机德州有没有... 您好,手机德州有没有挂这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在...
攻略教程,wepoker透视挂... 攻略教程,wepoker透视挂安装,菠萝智星德州透视方法手段(从来是有辅助挂)主打本地运行的 AI ...