๋ชฉ๋กpreventDefault() (1)

๐Ÿค ์€์ง€log ๐Ÿค

[REACT] beforeunload ํŽ˜์ด์ง€ ๋‚˜๊ฐˆ๋•Œ / ์ƒˆ๋กœ๊ณ ์นจ ํ• ๋•Œ alert ๋„์šฐ๊ธฐ

beforeunload ์ด๋ฒคํŠธ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ผ๋ฐ˜์ ์œผ๋กœ ํŽ˜์ด์ง€๋ฅผ ๋‹ซ๊ฑฐ๋‚˜ ์ƒˆ๋กœ๊ณ ์นจํ•  ๋•Œ, ๋ธŒ๋ผ์šฐ์ €๋ฅผ ๋‹ซ์„ ๋•Œ, ์ฃผ์†Œ ํ‘œ์‹œ์ค„์— ๋‹ค๋ฅธ URL์„ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๋งํฌ๋ฅผ ํด๋ฆญํ•  ๋•Œ ๋ฐœ์ƒํ•˜๋ฉฐ, ํŽ˜์ด์ง€๋ฅผ ๋‹ซ๊ธฐ ์ „์— ์–ด๋– ํ•œ ์กฐ์น˜๋ฅผ ์ทจํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ฃผ๋กœ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ €์žฅํ•  ๊ฒƒ์ธ์ง€ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๊ฑฐ๋‚˜, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์‚ฌ์šฉ ์ค‘์ธ ๋ฆฌ์†Œ์Šค๋ฅผ ์ •๋ฆฌํ•˜๋Š” ๋“ฑ์˜ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ• ๋•Œ ํ™œ์šฉ๋ฉ๋‹ˆ๋‹ค. ๐Ÿ”† React ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ useEffect(() => { const handleBeforeUnload = (event) => { event.preventDefault(); event.returnValue = ''; // ๋”์ด์ƒ ์ง€์›๋˜์ง€ ์•Š๋Š” ์†์„ฑ ์ด๋ผ๊ณ  ํ•œ๋‹ค. ์ž‘์„ฑํ•˜์ง€ ์•Š์•„๋„ ๋ฌด๋ฐฉ }; window.addEventListener('b..

๐Ÿ’™ React 2023. 11. 13. 16:27