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
hrefis the full url, same asurl.toString()protocolends with the colon character:search– a string of parameters, starts with the question mark?hashstarts with the hash character#- there may be also
userandpasswordproperties 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