我只需要在Angular应用程序的特定部分上激活暗模式。
为此,我标记了相应的路由,如下所示:
const routes: Routes = [
{
path: 'home',
component: MyHomeComponent,
data: {
darkModeCompatible: true,
},
},
我实现了这样的全局路由侦听器:
this.routerSubscription = this.router.events
.pipe(filter((event) => event instanceof NavigationEnd))
.subscribe((event) => {
const router = this.router;
// How to I access to the route data here ?
// [...] add/remove custom class on the body element
});
问题是:如何在此全局路由侦听器中访问路由数据?