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