gpt4 book ai didi

angular - 如何静音 "The feature name "路由器“状态中不存在...”ngrx/router-store 警告

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

当我将“@ngrx/router-store”添加到我的项目时,它会在开发模式下向应用控制台发送垃圾邮件,并使用以下消息发送单元测试结果:

The feature name "router" does not exist in the state, therefore createFeatureSelector cannot access it. Be sure it is imported in a loaded module using StoreModule.forRoot('router', ...) or StoreModule.forFeature('router', ...). If the default state is intended to be undefined, as is the case with router state, this development-only warning message can be ignored.

我尝试将router状态属性类型设置为

router: null |  RouterReducerState<SerializedRouterStateSnapshot>

和初始状态值

router: null

但它与仅接受 routerReducer 类型冲突

RouterReducerState<SerializedRouterStateSnapshot>

如何禁用此警告?老实说我觉得这很烦人。

最佳答案

这对我有帮助:不要使用createFeatureSelector来创建路由器功能选择器,而是使用createSelector

export const routerState = createSelector((state: State) => state.router, value => value)

出现此问题的原因是 createFeatureSelector logs a warning如果特征值等于未定义。上面的代码与原始实现等效,但没有日志。

更新: here's a PR旨在解决问题。

关于angular - 如何静音 "The feature name "路由器“状态中不存在...”ngrx/router-store 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58214913/

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