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

标签 angular typescript ngrx ngrx-router-store

当我将“@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/

相关文章:

javascript - Angular - 模板中调用的模型方法在无限循环中执行

typescript - 类型允许字段名称和自身和派生类的属性

javascript - 让 Angular 解析器等待图像

angular - 除非安装了 Redux Devtools,否则 ngrx Angular 应用程序无法运行

typescript - 替换集合中实体的最简洁方法

javascript - 无法在 Angular2 中显示从一个组件发送到另一组件的数组

html - 按钮文本仅在鼠标悬停时可见

javascript - 将输入值存储在 ionic Angular 为 5 的数组中

rxjs - Observable 不发出任何值

node.js - 更好的一对一和群聊方法 nodejs Socket.io