Comments (3)
Hi,
Thanks for this mini tutorial, it's working almost great ;-) . But I'm also having problems with lazy loaded routes. When I view my source I see that it is not rendering my content but instead it only shows
Do you have a solution for this. Because for SEO it's much needed. What I've did so far is:
index.js file inside functions folder:
require('zone.js/dist/zone-node');
const functions = require('firebase-functions');
const express = require('express');
const path = require('path');
const { enableProdMode } = require('@angular/core');
const { renderModuleFactory } = require('@angular/platform-server');
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist-server/main.bundle');
enableProdMode();
const index = require('fs')
.readFileSync(path.resolve(__dirname, './dist/index.html'), 'utf8')
.toString();
let app = express();
app.get('**', function (req, res) {
renderModuleFactory(AppServerModuleNgFactory, {
url: req.path,
document: index,
extraProviders: [
provideModuleMap(LAZY_MODULE_MAP)
]
}).then(html => res.status(200).send(html));
});
exports.ssr = functions.https.onRequest(app);
the app.server.module file I have this:
import { NgModule } from '@angular/core';
import { ServerModule } 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,
ServerModule,
ModuleMapLoaderModule
],
bootstrap: [AppComponent],
})
export class AppServerModule {}
And my routing module looks like this
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { ModuleWithProviders } from '@angular/core';
import { AboutComponent } from './pages/about/about.component';
import { PortfoliosComponent } from './pages/portfolios/portfolios.component';
import { ExamplesComponent } from './pages/examples/examples.component';
import { ContactComponent } from './pages/contact/contact.component';
import { HomeComponent } from './pages/home/home.component';
const appRoutes: Routes = [
{ path: '', loadChildren: './pages/home/home.module#HomeModule', pathMatch: 'full' },
{ path: 'over-ons', loadChildren: './pages/about/about.module#AboutModule' },
{ path: 'portfolio', loadChildren: './pages/portfolios/portfolios.module#PortfoliosModule' },
{ path: 'voorbeelden', loadChildren: './pages/examples/examples.module#ExamplesModule' },
{ path: 'contact', loadChildren: './pages/contact/contact.module#ContactModule' }
];
export const AppRouting: ModuleWithProviders = RouterModule.forRoot(appRoutes);
Thanks in advance
Brian
from angular-universal-firebase.
Unfortunately, I have not yet experimented with lazy loaded routes so I don't have a solution at this time.
from angular-universal-firebase.
Ok, thanks! This would be the last step for my project. If I figure it out I'll post it here.
from angular-universal-firebase.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-universal-firebase.