Description#
Replace the current window.location stub with a proper Location object per the WHATWG HTML spec. The Location object exposes URL components and provides navigation methods.
Requirements#
Properties (getters)#
href— full URL stringprotocol— scheme +:(e.g.,https:)host— hostname + port (e.g.,example.com:8080)hostname— hostname onlyport— port string (empty if default)pathname— path (e.g.,/page)search— query string including?hash— fragment including#origin— scheme + host (read-only)
Setters#
- Setting
hrefnavigates to the new URL - Setting
pathname,search,hash, etc. navigates to the modified URL - Setting
hashalone should trigger fragment navigation (no page reload)
Methods#
assign(url)— navigate to URL (adds history entry)replace(url)— navigate to URL (replaces current history entry)reload()— reload the current pagetoString()— returnshref
Acceptance Criteria#
- All Location properties return correct URL components for the current page
- Setting
location.href = '...'navigates to the new URL -
location.assign()navigates and adds a history entry -
location.replace()navigates without adding a history entry -
location.reload()re-fetches and re-renders the current page -
document.locationis the same object aswindow.location - Unit tests for all property getters and navigation methods