Location
How to use the Location class of the bit Butil?
Usage
To use the browser location features you need to inject the Bit.Butil.Location class and use it like this:
@inject Bit.Butil.Location location @code { await location.Reload(); }
Methods
SetHref, GetHref:
Gets/Sets the href of the location and then the associated document navigates to the new page (MDN).
@inject Bit.Butil.Location location <BitTextField @bind-Value="newHref" /> <BitButton OnClick="@SetHref">SetHref</BitButton> <BitButton OnClick="@GetHref">GetHref</BitButton> <div>Href: @currentHref</div> @code { private string? newHref; private string? currentHref; private async Task GetHref() { currentHref = await location.GetHref(); } private async Task SetHref() { await location.SetHref(newHref!); } }
SetProtocol, GetProtocol:
Gets/Sets a string containing the protocol scheme of the URL, including the final ':' (MDN).
@inject Bit.Butil.Location location <BitTextField @bind-Value="newProtocol" /> <BitButton OnClick="@SetProtocol">SetProtocol</BitButton> <BitButton OnClick="@GetProtocol">GetProtocol</BitButton> <div>Protocol: @currentProtocol</div> @code { private string? newProtocol; private string? currentProtocol; private async Task GetProtocol() { currentProtocol = await location.GetProtocol(); } private async Task SetProtocol() { await location.SetProtocol(newProtocol!); } }
SetHost, GetHost:
Gets/Sets a string containing the host, that is the hostname, a ':', and the port of the URL (MDN).
@inject Bit.Butil.Location location <BitTextField @bind-Value="newHost" /> <BitButton OnClick="@SetHost">SetHost</BitButton> <BitButton OnClick="@GetHost">GetHost</BitButton> <div>Host: @currentHost</div> @code { private string? newHost; private string? currentHost; private async Task GetHost() { currentHost = await location.GetHost(); } private async Task SetHost() { await location.SetHost(newHost!); } }
SetHostname, GetHostname:
Gets/Sets the hostname of the location and then the associated document navigates to the new page (MDN).
@inject Bit.Butil.Location location <BitTextField @bind-Value="newHostname" /> <BitButton OnClick="@SetHostname">SetHostname</BitButton> <BitButton OnClick="@GetHostname">GetHostname</BitButton> <div>Hostname: @currentHostname</div> @code { private string? newHostname; private string? currentHostname; private async Task GetHostname() { currentHostname = await location.GetHostname(); } private async Task SetHostname() { await location.SetHostname(newHostname!); } }
SetPort, GetPort:
Gets/Sets the port of the location and then the associated document navigates to the new page (MDN).
@inject Bit.Butil.Location location <BitTextField @bind-Value="newPort" /> <BitButton OnClick="@SetPort">SetPort</BitButton> <BitButton OnClick="@GetPort">GetPort</BitButton> <div>Port: @currentPort</div> @code { private string? newPort; private string? currentPort; private async Task GetPort() { currentPort = await location.GetPort(); } private async Task SetPort() { await location.SetPort(newPort!); } }
SetPathname, GetPathname:
Gets/Sets a string containing an initial '/' followed by the path of the URL, not including the query string or fragment (MDN).
@inject Bit.Butil.Location location <BitTextField @bind-Value="newPathname" /> <BitButton OnClick="@SetPathname">SetPathname</BitButton> <BitButton OnClick="@GetPathname">GetPathname</BitButton> <div>Pathname: @currentPathname</div> @code { private string? newPathname; private string? currentPathname; private async Task GetPathname() { currentPathname = await location.GetPathname(); } private async Task SetPathname() { await location.SetPathname(newPathname!); } }
SetSearch, GetSearch:
Gets/Sets a string containing a '#' followed by the fragment identifier of the URL (MDN).
@inject Bit.Butil.Location location <BitTextField @bind-Value="newSearch" /> <BitButton OnClick="@SetSearch">SetSearch</BitButton> <BitButton OnClick="@GetSearch">GetSearch</BitButton> <div>Search: @currentSearch</div> @code { private string? newSearch; private string? currentSearch; private async Task GetSearch() { currentSearch = await location.GetSearch(); } private async Task SetSearch() { await location.SetSearch(newSearch!); } }
SetHash, GetHash:
Gets/Sets the hash of the location and then the associated document navigates to the new page (MDN).
@inject Bit.Butil.Location location <BitTextField @bind-Value="newHash" /> <BitButton OnClick="@SetHash">SetHash</BitButton> <BitButton OnClick="@GetHash">GetHash</BitButton> <div>Hash: @currentHash</div> @code { private string? newHash; private string? currentHash; private async Task GetHash() { currentHash = await location.GetHash(); } private async Task SetHash() { await location.SetHash(newHash!); } }
GetOrigin:
Returns a string containing the canonical form of the origin of the specific location (MDN).
@inject Bit.Butil.Location location <BitButton OnClick="@GetOrigin">GetOrigin</BitButton> <div>Origin: @currentOrigin</div> @code { private string? currentOrigin; private async Task GetOrigin() { currentOrigin = await location.GetOrigin(); } }
Assign:
Loads the resource at the URL provided in parameter (MDN).
@inject Bit.Butil.Location location <BitTextField @bind-Value="newAssign" /> <BitButton OnClick="@SetAssign">Assign</BitButton> @code { private string? newAssign; private async Task SetAssign() { await location.Assign(newAssign!); } }
Reload:
Reloads the current URL, like the Refresh button (MDN).
@inject Bit.Butil.Location location <BitButton OnClick="@(() => location.Reload())">Reload</BitButton>
Replace:
Replaces the current resource with the one at the provided URL (redirects to the provided URL) (MDN).
@inject Bit.Butil.Location location <BitTextField @bind-Value="newReplace" /> <BitButton OnClick="@SetReplace">Replace</BitButton> @code { private string? newReplace; private async Task SetReplace() { await location.Replace(newReplace!); } }