gpt4 book ai didi

Angular:更新路由数据

转载 作者:行者123 更新时间:2023-12-05 07:35:00 25 4
gpt4 key购买 nike

我有一个使用 ngx-breadcrumbs 的 Angular 5 应用程序。面包屑设置为路由内的数据,如下所示:

{ path: 'event-template', component: EventTemplateComponent, data: { breadcrumbs: 'New Event'} }

我想稍后从一个组件中更新这个面包屑,这样:

ngOnInit() {
this.activatedRoute.data.subscribe((currentData) => {
currentData['breadcrumbs'] = 'newValue';
});
}

显然,我希望在页面加载之前更新面包屑的值。以便新字符串优先。但我不知道该怎么做,我认为上面的方法不一定正确。谁能帮忙?

谢谢!

最佳答案

与其在路由参数上分配新值,不如使用 router.navigate 方法触发另一个路由事件。你可以做类似this.router.navigate('event-template', {breadcrumbs: 'New Event'})

关于Angular:更新路由数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49822150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com