To get the page referrer of where the user came from, follow these steps:
-
Create a JavaScript function as a separate file in your application (~/wwwroot/interop.js).
function getPageReferrer() { return document.referrer; } -
Add the script reference in the ~/wwwroot/index.html file of the Blazor WebAssembly application.
<script src="interop.js"></script> -
Invoke the JavaScript function using the IJSRuntime service in a Razor page.
@page "/" @inject IJSRuntime JSRuntime @code { protected override async Task OnInitializedAsync() { var pageReferrer = await JSRuntime.InvokeAsync<string>("getPageReferrer"); } }


Share with