Я пытаюсь изменить свой веб-сайт, чтобы использовать угловую универсальность в Firebase.
Итак, после настройки моего сервера (экспресс) я получаю сообщение об ошибке:
TypeError: Cannot read property 'root' of undefined
at new rootRoute (/user_code/node_modules/@angular/router/bundles/router.umd.js:5390:34)
at _createClass (/user_code/node_modules/@angular/core/bundles/core.umd.js:8445:24)
at _createProviderInstance (/user_code/node_modules/@angular/core/bundles/core.umd.js:8417:30)
at initNgModule (/user_code/node_modules/@angular/core/bundles/core.umd.js:8350:36)
at new NgModuleRef_ (/user_code/node_modules/@angular/core/bundles/core.umd.js:9076:13)
at Object.createNgModuleRef (/user_code/node_modules/@angular/core/bundles/core.umd.js:9065:16)
at NgModuleFactory_.create (/user_code/node_modules/@angular/core/bundles/core.umd.js:11607:29)
at /user_code/node_modules/@angular/core/bundles/core.umd.js:4375:47
at ZoneDelegate.invoke (/user_code/node_modules/zone.js/dist/zone-node.js:388:26)
at Object.onInvoke (/user_code/node_modules/@angular/core/bundles/core.umd.js:3890:37)
это мой код сервера:
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 { AppServerModuleNgFactory } = require('./dist/server/main');
enableProdMode();
const index = require('fs')
.readFileSync(path.resolve(__dirname, './dist/browser/index.html'), 'utf8')
.toString();
let app = express();
app.get('**', function(req, res) {
renderModuleFactory(AppServerModuleNgFactory, {
url: req.path,
document: index
}).then(html => res.status(200).send(html));
});
exports.ssr = functions.https.onRequest(app);
и это мой app.routes.ts
import { ArtistaComponent } from './component/site/artista/artista.component';
import { CifraComponent } from './component/site/cifra/cifra.component';
import { HomeComponent } from './component/site/home/home.component';
import { Routes, RouterModule } from "@angular/router";
import { ModuleWithProviders, NgModule } from '@angular/core';
export const ROUTES: Routes = [
{ path: '' , component: HomeComponent },
{ path: 'cifra/:artista/:musica' , component: CifraComponent},
{ path: 'artista/:artista' , component: ArtistaComponent}
]
export const routes: NgModule = RouterModule.forRoot(ROUTES);
@NgModule({
imports: [
RouterModule.forChild(ROUTES)
]
})
export class AppRoutingModule {}
Так что я много чего пробовал, но не смог решить эту проблему.