我如何从 typesafe redux-observable epic 中收听 '@@router/LOCATION_CHANGE' 动作

How do I listen to '@@router/LOCATION_CHANGE' action from typesafe redux-observable epic

我正在尝试收听类型安全 redux-observable 史诗中的 '@@router/LOCATION_CHANGE' 动作,但我只是不明白该怎么做。

  1. 我需要过滤的确切操作是什么?我尝试 'filter(onLocationChanged)' 失败。
  2. 什么是正确的 'IN' 类型?使用 'LocationChangeAction''filter(onLocationChanged)' 我得到类型错误:

No overload matches this call.

  1. 最后,如何通过 '@@router/LOCATION_CHANGE' 操作更改位置? (前后)
import { Epic } from "redux-observable";
import { of } from "rxjs";
import { filter, withLatestFrom, concatMap } from "rxjs/operators";
import { AppState } from "../../reducer";
import { CallHistoryMethodAction, LOCATION_CHANGE, push, onLocationChanged, RouterActionType, LocationChangeAction } from 'connected-react-router';


type IN = LocationChangeAction;
type OUT = ReturnType<typeof somthing>;

export const LocationListenEpic: Epic<IN | OUT, OUT, AppState> = (
    action$,
    state$
) => 
    action$.pipe(
        filter(onLocationChanged),
        withLatestFrom(state$),
        concatMap(([{ payload }, state]) => {

            console.log(currentLocation);
            return []
}

深入了解 redux-observable epics 的工作原理后:


import { getLocation } from 'connected-react-router'

type IN = LocationChangeAction;
type OUT = ReturnType<typeof somthing>;

export const LocationListenEpic: Epic<IN | OUT, OUT, AppState> = (
    action$,
    state$
) => 
    action$.pipe(
        filter(action => action.type == LOCATION_CHANGE),
        withLatestFrom(state$),
        concatMap(([{ payload }, state]) => {

            console.log(getLocation(store.getState()));
            return []
}