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,

相关内容

热门资讯

玩家必看科普!微乐小程序麻将自... 玩家必看科普!微乐小程序麻将自建房辅助工具插件,微乐家乡麻将自建房辅助app(开挂自建房)插件1、微...
玩家必看科普!微乐小程序自建房... 玩家必看科普!微乐小程序自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)器微乐小程序自建房辅...
科普!微乐自建房辅助工具插件,... 您好,微乐家乡麻将自建房辅助app这款游戏可以开挂的,确实是有挂的,需要了解加去威信【1367043...
我来向大家传授!微乐自建房辅助... 我来向大家传授!微乐自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)攻略1)微乐自建房辅助工...
科技新动态!微乐自建房辅助工具... 科技新动态!微乐自建房辅助工具脚本,微乐小程序免费黑科技(开挂自建房)器1)微乐自建房辅助工具脚本有...
重要通知!微乐自建房辅助工具挂... 重要通知!微乐自建房辅助工具挂,微乐小程序免费黑科技(开挂自建房)插件1、玩家可以在微乐自建房辅助工...
科普分享!微乐小程序麻将自建房... 科普分享!微乐小程序麻将自建房辅助工具插件,微乐家乡麻将自建房辅助app(开挂自建房)插件一、微乐小...
每日必备!微乐自建房辅助工具插... 每日必备!微乐自建房辅助工具插件,微乐家乡麻将自建房辅助app(开挂自建房)器1、在微乐家乡麻将自建...
玩家必看科普!微乐自建房辅助工... 玩家必看科普!微乐自建房辅助工具脚本,微乐小程序免费黑科技(开挂自建房)方法1、完成微乐自建房辅助工...
专业讨论!微信雀神麻将挂件开挂... 专业讨论!微信雀神麻将挂件开挂辅助,微乐小程序免费黑科技(开挂自建房)器1、很好的工具软件,可以解锁...