routing

๐Ÿ“ Location & Pathname

Window.location ์€ ํ˜„์žฌ URL ์ •๋ณด๋ฅผ ๊ฐ€์ง„ Location ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

location object

์˜ˆ์‹œ ์ฃผ์†Œ : http://www.example.com:8080/products?id=1234&page=1#top

  • location.href ์ „์ฒด URL์ด ํฌํ•จ๋œ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. http://www.example.com:8080/products?id=1234&page=1#top

  • location.protocol ํ”„๋กœํ† ์ฝœ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. http:

  • location.host ํ˜ธ์ŠคํŠธ ์ด๋ฆ„๊ณผ ํฌํŠธ ๋ฒˆํ˜ธ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. www.example.com:8080

  • location.hostname ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. www.example.com

  • location.pathname ๊ฒฝ๋กœ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. /products

  • location.search ์ฟผ๋ฆฌ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ?id=1234&page=1

  • location.hash ํ•ด์‹œ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. #top

Location Instance Method

  • assign(url) ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์€ url์„ ์ƒˆ๋กœ์šด ๋ฌธ์„œ์— ๋กœ๋“œํ•œ๋‹ค.

  • reload() ํ˜„์žฌ ๋ฌธ์„œ๋ฅผ ๋‹ค์‹œ ๋กœ๋“œํ•œ๋‹ค.

  • replace(url) ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์€ url์„ ์ƒˆ๋กœ์šด ๋ฌธ์„œ์— ๋กœ๋“œํ•œ๋‹ค. ์ด์ „ ๋ฌธ์„œ๋Š” history์— ๋‚จ์ง€ ์•Š๋Š”๋‹ค.

  • toString() ์ „์ฒด URL์ด ํฌํ•จ๋œ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.


โœ๏ธ ์ •๋ฆฌ

  • ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ

Last updated