angular 7 中的中间件?

Middleware in angular 7?

有没有像laravel这样的中间件angular 7 或者如何通过路由设置站点的语言? (https://example.com/en/about, https://example.com/de/about)

P.S。目前我正在使用 this method 多语言。

您可以 subscribe 路由器事件,并在 NavigationStart 上更改您提到的 translationService 方法中使用的语言,但我强烈建议您使用 ngx-translate

this.router.events.subscribe((event: any): void => {
  if (event instanceof NavigationStart) {
     /* You should parse for the language code in the route
       here and use it in the following line. Also make sure that the parsed
       language code is an actual language code */
     this.translationService.use(languageCode).then(() => // do your stuff);
  }
});