NestJS Angular Universal不会在根路径上自动加载“ index.html”

问题描述 投票:0回答:1

我正在使用Angular 9和Ivy在本地服务器上运行NestJS Angular Universal应用。运行时,我可以使所有工作正常进行:

npm run serve:ssr

但是,除非我手动输入路线,否则不会加载任何内容。我认为它无需输入就可以自动加载“ index.html”。

localhost:8080 -----没什么

localhost:8080 / index.html ----可行

是否可以修改代码以对根路径进行重写?我认为这是没有必要的:

main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.setGlobalPrefix('api');
  await app.listen(process.env.PORT || 8080);
}

// Webpack will replace 'require' with '__webpack_require__'
// '__non_webpack_require__' is a proxy to Node 'require'
// The below code is to ensure that the server is run only when not requiring the bundle.
declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = (mainModule && mainModule.filename) || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
  bootstrap().catch(err => console.error(err));
}

或解决当前问题...

我正在使用Angular 9和Ivy在本地服务器上运行NestJS Angular Universal应用。运行时,我可以使所有工作正常进行:npm run serve:ssr但是,除非输入路由,否则什么也不会加载...

nestjs angular-universal angular9
1个回答
0
投票

[经过几天的努力,我发现通过包含一个组件而存在一个循环,该组件包含另一个在ts文件中具有循环的组件。就我而言,我正在订阅我不应该拥有的东西。我以为这是IVY / NestJS兼容性问题,但事实证明这是我的代码。

© www.soinside.com 2019 - 2024. All rights reserved.