ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๋ฌธ์ œ

ํ”„๋กœ์ ํŠธ ๋„์ค‘ ๊ฒ€์ƒ‰์ฐฝ์— ์˜์–ด๋ฅผ ์น˜๋ฉด ๋ณ„ ๋ฌธ์ œ ์—†์ด ์ฟผ๋ฆฌ ๊ฐ’์„ API path์— ๋‹ด์•„ ์„œ๋ฒ„์—์„œ ๊ด€๋ จ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฌด์‚ฌํžˆ ๊ฐ€์ ธ์˜ค์ง€๋งŒ, ํ•œ๊ธ€์„ ์น  ๊ฒฝ์šฐ์—๋Š” ํ•ด๋‹น keyword์˜ ๊ฐ’์ด ๊นจ์ง„ ์ƒํƒœ๋กœ ์ฟผ๋ฆฌ ๊ฐ’์„ ์„œ๋ฒ„์— ๋ณด๋‚ด ์ œ๋Œ€๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋‹ค.

 

๋ฌธ์ œํ•ด๊ฒฐ_encodeURI

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/encodeURI

 

encodeURI() - JavaScript | MDN

encodeURI() ํ•จ์ˆ˜๋Š” URI์˜ ํŠน์ •ํ•œ ๋ฌธ์ž๋ฅผ UTF-8๋กœ ์ธ์ฝ”๋”ฉํ•ด ํ•˜๋‚˜, ๋‘˜, ์…‹, ํ˜น์€ ๋„ค ๊ฐœ์˜ ์—ฐ์†๋œ ์ด์Šค์ผ€์ดํ”„ ๋ฌธ์ž๋กœ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

developer.mozilla.org

The encodeURI() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).

 

์ฐพ์•„๋ณด๋‹ˆ ํ•œ๊ธ€ ๋ฌธ์ž์—ด์„ ์ฟผ๋ฆฌ์— ํฌํ•จ์‹œํ‚ค๊ธฐ ์ „์—๋Š” ์ธ์ฝ”๋”ฉํ•˜๋Š” ์ž‘์—…์ด ๋ณ„๋„๋กœ ํ•„์š”ํ–ˆ์—ˆ๋‹ค.

์ด์— API ํ†ต์‹ ์„ ํ•˜๊ธฐ ์ „์— ๋ฐ›์•„ ์˜จ keyword ๊ฐ’์ด ํ•œ๊ธ€์ผ ๊ฒฝ์šฐ์—๋Š” ํ•ด๋‹น keyword๋ฅผ encodeURI() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ฝ”๋”ฉํ•ด์ฃผ๋Š” ์ž‘์—…์„ ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•จ์œผ๋กœ์จ, ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค.

( ... )

const checkHasIncode = keyword => {
  const check_kor = /[ใ„ฑ-ใ…Ž|ใ…-ใ…ฃ|๊ฐ€-ํžฃ]/; // ํ•œ๊ธ€์ธ์ง€ ์‹๋ณ„ํ•ด์ฃผ๊ธฐ ์œ„ํ•œ ์ •๊ทœํ‘œํ˜„์‹

  if (keyword.match(check_kor)) {
    const encodeKeyword = encodeURI(keyword); // ํ•œ๊ธ€ ์ธ์ฝ”๋”ฉ
    return encodeKeyword;
  } else {
    return keyword;
  }
};

export const searchKeyword = keyword => {
  return client.get(
    `${API.baseUrl}contents/search?keyword=${checkHasIncode(keyword)}`
  );
};

 

๊ฒฐ๊ณผํ™”๋ฉด

๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
TAG
more
ยซ   2025/01   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
๊ธ€ ๋ณด๊ด€ํ•จ