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辅助工具收费多少,揭秘教程(有挂技巧)1、不需要AI权限,帮助...
让我来分享经验!wepoker... 让我来分享经验!wepoker游戏安装教程,wpk辅助插件,必赢教程(有挂神器);大神普及一款德州a...
免费测试版!xpoker辅助怎... 您好,wepoker钻石怎么看底牌这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302...
新手必备!pokemmo辅助脚... 新手必备!pokemmo辅助脚本,We poker辅助器下载,2025新版教程(有挂辅助),支持语音...
实测揭晓!wepoker插件辅... 实测揭晓!wepoker插件辅助,pokerworld辅助器,揭秘教程(有挂辅助);1分钟了解详细教...
查到实测!pokerworld... 查到实测!pokerworld软件,hh poker辅助有用吗,辅助教程(有挂技巧)1、很好的工具软...
玩家必看科普!wepoker破... 1、玩家必看科普!wepoker破解版内购,hhpoker到底可以作弊吗,揭秘攻略(有挂教程);详细...
玩家必备科技!wepoker钻... 玩家必备科技!wepoker钻石怎么看底牌,hhpoker开挂教程,玩家教程(有挂方法),支持语音通...
最新技巧!智星德州插件怎么下载... 1、最新技巧!智星德州插件怎么下载,大菠萝手游辅助,攻略教程(有挂透视)2、进入游戏-大厅左侧-新手...
科技通报!pokemmo脚本辅... 您好,pokemmo脚本辅助器下载这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302...