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,

相关内容

热门资讯

玩家必备科技!微信闲来神器软件... 玩家必备科技!微信闲来神器软件下载(辅助挂)aapoker透视插件(从来真的是有挂)是一款可以让一直...
科技揭秘!丰城双剑辅助(辅助挂... 科技揭秘!丰城双剑辅助(辅助挂)aapoker发牌逻辑(先前有挂)是一款可以让一直输的玩家,快速成为...
玩家必备科普!围棋辅助器乐乐(... 玩家必备科普!围棋辅助器乐乐(辅助挂)wpk辅助购买(真是真的是有挂);围棋辅助器乐乐免费下载原版,...
2024教程!混沌休闲辅助(辅... 2024教程!混沌休闲辅助(辅助挂)aapoker破解侠是真的吗(先前存在有挂);2024教程!混沌...
玩家必用!潮友会鱼虾蟹脚本辅助... 玩家必用!潮友会鱼虾蟹脚本辅助器(辅助挂)哈糖大菠萝免费辅助器(总是有挂);1、这是跨平台的潮友会鱼...
教学盘点!佛手在线破解(辅助挂... 教学盘点!佛手在线破解(辅助挂)wepoker手机版透视脚本(原本是有挂)是一款可以让一直输的玩家,...
科技分享!丽水茶苑脚本(辅助挂... 科技分享!丽水茶苑脚本(辅助挂)wepoker私人局规律(往昔真的有挂);小薇(透视辅助)致您一封信...
实操分享!胡乐胡乐辅助脚本可靠... 实操分享!胡乐胡乐辅助脚本可靠吗(辅助挂)来玩app破解版(原先存在有挂);1、超多福利:超高返利,...
一分钟揭秘!微信决胜游戏辅助(... 【福星临门,好运相随】;一分钟揭秘!微信决胜游戏辅助(辅助挂)hhpoker免费透视脚本(素来是真的...
玩家必知教程!哈狗智能辅助(辅... 玩家必知教程!哈狗智能辅助(辅助挂)hhpoker真的有透视吗(好像真的有挂)是一款可以让一直输的玩...