[英]How to wait or listen for Url has changed using rxjs and redux-observable?
I'm trying to show modal popup after I received response data and after I go to another page. 我收到响应数据后并转到另一页后,试图显示模式弹出窗口。 Hot to implement this correctly?
正确实施此功能很热吗?
Iuse React-observable and rxjs . 我使用React-observable和rxjs 。 I did create an epic using with requests to server and changing history.location.
我确实使用请求服务器和更改history.location来创建史诗。 It works fine
工作正常
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()),
),
),
I want to see the 'Success' modal popup after I am on a new route. 在上一条新路线后,我想看到“成功”模态弹出窗口。 So I want to listen history.push, or verify if I am on a new route and only then to show the modal
所以我想听history.push,或验证我是否在新路线上,然后才显示模态
I don't believe it's possible to execute that logic the way you explained it (with react-router
atleast). 我不认为有可能按照您解释它的方式执行该逻辑(至少使用
react-router
)。
However, if /newRoute
is only reachable through the success of this action, you could just open the modal when the component corresponding to newRoute
mounts. 但是,如果仅通过此操作成功才能访问
/newRoute
则可以在安装与newRoute
对应的组件时打开模式。
Otherwise, provide a query param to determine whether or not you would like to open the modal. 否则,请提供查询参数以确定您是否要打开模式。
For example: 例如:
// 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();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.