Angular Universal Firebase-TypeError:无法读取未定义的属性“ root”

时间:2019-01-11 00:47:11

标签: angular firebase express angular-universal

我正尝试将我的网站更改为在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 {}

所以我尝试了很多事情,但无法解决这个问题。

0 个答案:

没有答案