Angular SSR时通用路由参数

Angular Universal with Route Param when SSR

我的 Angular 通用应用程序 (v8.1.1) 出现了一个奇怪的问题。

我在通用存储库中看不到任何相关的当前或过去的问题。

我的代码的一个简单示例:

路线:

export const routes = [
  {
    path: '',
    component: ParentComponent,
    children: [
      {
        path: ':routeParam',
        component: ChildComponent
      }
    ]
  }
];

组件:

...
export class ChildComponent {

  id: string;

  constructor( private route: ActivatedRoute ) {
    this.id = this.route.snapshot.params[ 'routeParam' ]; // get unexpected values eg. favicon.ico
  }

}

server.ts:

...

app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));

app.get('*.*', express.static( join(DIST_FOLDER, 'browser') ) );

app.get('*', (req, res) => {
    res.render('index', { req, res });
});

动态路由(带有参数)在浏览器呈现时工作正常,但在服务器端呈现时则不然。

它超时并中断。

当服务器端呈现时,它接收 favicon.icobg.svg 作为 routeParam 值(以及预期的字符串值)。

这些文件是 domain/assets/.. 文件夹中提供的资产。

所以我不明白他们是如何得到组件路由参数的。

我做错了什么?

来自快递serve static middleware documentation

When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware,

我认为由于某种原因 express 找不到静态文件 favicon.icobg.svg,所以它会调用下一个中间件,由 angular 应用程序及其应用程序处理路由。

确保 dist\browser 文件夹包含您要查找的文件。如果是,请在从 angular

调用这些文件时尝试检查这些文件的相对路径