11.19航海68日目TIL
pathNameのインポート
loadTalkRoomListToAxios()
が発行される.// chat 보냈을 때 채팅방에 둘다 있을 때 타입 0
// chat 보냈을 때 채팅방에 한명만 있고 상대방은 로그인 했을 때 타입 1
// chat 보냈을 때 상대방이 로그아웃 타입 2
// tap 요청 받았을 때 타입 3
// tap 요청 거절한게 타입 4
// tap 요청 수락한게 타입 5
if (newNoti.type === 1) {
console.log('채팅알람!');
console.log('디패 로드 톡룸');
await dispatch(loadTalkRoomListToAxios());
dispatch(setChatNoti(true));
}


user Bは/Gabtalkページ上でのみスケジューリングされるため、コードを変更しました.
const pageCheck = window.location.pathname;
if (newNoti.type === 1) {
if (pageCheck === '/grabtalk') {
console.log('디패 로드 톡룸');
await dispatch(loadTalkRoomListToAxios());
}
dispatch(setChatNoti(true));
}

動作が正常なので、いろいろなテストをしているうちに、ホームページに戻り、チャットページに着くと、pathnameが飛んでいて、プレビューが更新されていないという問題が見つかりました.

urlを取得する方法をいくつか試しました
import { useHistory, useLocation } from 'react-router-dom';
const history = useHistory();
const location = useLocation();
const pageCheck = window.location.href.split('/');
const nowPage = pageCheck[pageCheck.length - 1];
const nowPageE = window.location.pathname;
if (newNoti.type === 1) {
console.log(
'nowPageE = window.location.pathname ===>',
nowPageE,
);
console.log('location ====>', location);
console.log('history ====>', history);
console.log('nowPage ====>', nowPage);
console.log(
'pageCheck = window.location.href.split("/") ====>',
pageCheck,
);
if (nowPage === '/grabtalk') {
console.log('디패 로드 톡룸');
await dispatch(loadTalkRoomListToAxios());
}
dispatch(setChatNoti(true));
}

const nowPage = history.location.pathname;
if (newNoti.type === 1) {
console.log('history.location.pathname ====>', nowPage);
console.log('history ====>', history);
if (nowPage === '/grabtalk') {
console.log('디패 로드 톡룸');
await dispatch(loadTalkRoomListToAxios());
}
dispatch(setChatNoti(true));
}

if (newNoti.type === 1) {
if (history.location.pathname === '/grabtalk') {
console.log('디패 로드 톡룸');
await dispatch(loadTalkRoomListToAxios());
}
dispatch(setChatNoti(true));
}

Reference
この問題について(11.19航海68日目TIL), 我々は、より多くの情報をここで見つけました https://velog.io/@wswj9608/11.19-항해-68일차-TILテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol