javascript - 如何使用 rxjs 和 redux-observable 等待或监听 Url 已更改?

标签 javascript rxjs reactive-programming

我试图在收到响应数据后并转到另一个页面后显示模式弹出窗口。热衷于正确实现这一点吗?

我使用React-observablerxjs。我确实使用服务器请求和更改历史记录创建了一个史诗。效果很好

action$.pipe(
    ofType(myActionLading),
    mergeMap(action => of(convertDataToServer(action.payload))),
    mergeMap(data =>
      from(convertToDataAPI(data)).pipe(
        mergeMap(response => of(convertCustomerFromServer(response.
        mergeMap(() => {
         return of(
          actionGetDataInfoLoading({ id }),
          );
        }),
        tap(() => history.push('/newRoute')),
takeUntil(// I have to verify if I am already on my newRoute and then show the popUp),
        finalize(() => console.log('!!! FIN !!!') || 
          modals.getModalSuccess()),
   ),
    ),

我想在走新路线后看到“成功”模式弹出窗口。所以我想听history.push,或者验证我是否在新路线上,然后才显示模式

最佳答案

我不相信可以按照您解释的方式执行该逻辑(至少使用react-router)。

但是,如果只有通过此操作成功才能访问 /newRoute,则您可以在安装 newRoute 对应的组件时打开模态框。

否则,请提供一个查询参数来确定您是否要打开模式。

例如:

// someEpic.js
tap(() => history.push('/newRoute?showModal=true')

...

//newRoute.jsx (The component)
export class NewRoute extends React.Component {
   ...
   componentWillMount() {
       const showModal = this.props.... // logic to get query param of showModal.

       if (showModal) {
          modals.getModalSuccess();
       }
   }
}

关于javascript - 如何使用 rxjs 和 redux-observable 等待或监听 Url 已更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55864113/

相关文章:

javascript - 在 Canvas 中创建像动画一样嘈杂的混沌波

javascript - 当没有 "next"照片可用时使用 Vue.js : disabling button on picture slideshow,

javascript - RxJS publishReplay 与 publishLast

swift - ReactiveCocoa - 具有一般错误处理功能的信号生成器序列

javascript - RxJS - 初始状态和更新

javascript - 我如何使用 RxJs 推迟对 AJAX 调用的任何请求,直到前一个请求解决

javascript - 在 Angular 2 中使用 jQuery

javascript - 如何捕获在 contenteditable div 内单击的特定字符

Angular 2和rxjs : ngIf according to a Subject

javascript - RxJS:auditTime 和 sampleTime 之间的区别?