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、金币登录送、破产送、升级...
透视工具!hhpoker透视脚... 透视工具!hhpoker透视脚本下载,福建天天开心辅助器,透明教程(有挂透视);福建天天开心辅助器软...
记者揭秘!aa扑克有挂吗,we... 一、wepower有外挂简介了解软件请加微:136704302wepower有外挂是一款在线扑克游戏...
透视最新!aapoker可以开... 透视最新!aapoker可以开挂吗,途游四川小程序脚本辅助,软件教程(有挂神器)1、不需要AI权限,...
我来分享!wpk德州胜利跟号有... 我来分享!wpk德州胜利跟号有关么,aapoker辅助工具存在,介绍教程(本来有挂)您好,aapok...
透视脚本!wepoker辅助器... 透视脚本!wepoker辅助器怎么用,顺欣茶楼怎么开挂,2025版教程(有挂透明)是一款可以让一直输...
揭秘真相!wpk ai机器人和... 揭秘真相!wpk ai机器人和真的的区别,wepoke有没有挂,AI教程(一贯真的有挂);致您一封信...
透视脚本!hhpoker透视功... 透视脚本!hhpoker透视功能如何下载,wepoker辅助软件价格,大神讲解(有挂方法);致您一封...
交流学习经验!aapoker线... 一、WPK透视辅助简介了解软件请加微:136704302WPK透视辅助是一款在线扑克游戏平台,玩家可...
透视透视!wepoker辅助工... 透视透视!wepoker辅助工具,多乐辅助下载够机,攻略方法(有挂技巧)1、很好的工具软件,可以解锁...