URL Structure:

https://site.com:8080/blog/angular?p1=device1#specification

Origin:

  • protocol = https
  • host = site.com
  • port = 8080
  • pathname = blog,angular
  • query prams(search)
  • hash = #specification

Notes about URL

  1. href is the full url, same as url.toString()
  2. protocol ends with the colon character :
  3. search – a string of parameters, starts with the question mark ?
  4. hash starts with the hash character #
  5. there may be also user and password properties if HTTP authentication is present: http://login:password@site.com (not painted above, rarely used).

Get Current url path from current url

@const pathArray = window.location.pathname.split('/');

  @alert(pathArray[2]);

URL Encoding

let url = new URL('https://ru.example.org/wiki/Тест');

url.searchParams.set('key', 'ъ');

alert(url); 

output is: https://ru.example.org/wiki/%D0%A2%D0%B5%D1%81%D1%82?key=%D1%8A