Angular5 Universal lazy loading on firebase hosting and seo

倾然丶 夕夏残阳落幕 提交于 2019-12-11 06:04:28

问题


Does anyone know howto get lazyloading on firebase hosting working? It all works but when I view the source code of my site, I only see the router-outlet and not the text and so on. I've added the code below to my index.js inside the functions folder:

extraProviders: [
  provideModuleMap(LAZY_MODULE_MAP)
]

My app.server.module file looks like this:

import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server';
import { AppModule } from './app.module';
import { AppComponent } from './app.component';

@NgModule({
imports: [
AppModule,
ServerModule
],
bootstrap: [AppComponent],
})
export class AppServerModule {}

But when I use firebase deploy in my console, it has deployed succesfully. However when I visit my site after that, I get an error and a blank page.

So if anyone can point me to the right direction, that would be awesome !


回答1:


It may be because you are missing the ModuleMapLoaderModule module in your imports

app.server.module.ts

import {ModuleMapLoaderModule} from '@nguniversal/module-map-ngfactory-loader'

@NgModule({
imports: [
AppModule,
ServerModule,
ModuleMapLoaderModule
],

It seems to be needed for lazy loaded routes:

The ModuleMapLoaderModule is a server-side module that allows lazy-loading of routes.

https://angular.io/guide/universal#app-server-module



来源:https://stackoverflow.com/questions/49038948/angular5-universal-lazy-loading-on-firebase-hosting-and-seo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!