peterblazejewicz / blazor-beforeunload

Blazor hook into native Window beforeunload with async/await and cancel support
https://www.nuget.org/packages/BlazorBeforeUnload/
MIT License
21 stars 6 forks source link

Any plans to make it Blazor Server-Side compatible? #2

Open CoSJay opened 4 years ago

CoSJay commented 4 years ago

This is exactly what I need (I have no idea why the Blazor folk didn't include it!), but as client-side Blazor isn't released yet we can't use it for production apps -- we're doing everything server-side. Any thought to making this SSB-friendly?

peterblazejewicz commented 4 years ago

@CoSJay I'm most accustomed to client-side blzr, let me look into the problem for server side. Thanks!

pentiv commented 3 years ago

Hi peter,

do you have any solution, blazor server side web assembly.

https://github.com/peterblazejewicz/blazor-beforeunload/issues/2

please let me know that will be great help.

peterblazejewicz commented 3 years ago

can't promise, I need to refresh local stack, tbu

jmarinl commented 2 years ago

Please help me on blazor server. Error. Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: blazejewicz.Blazor.BeforeUnload.BeforeUnload Lifetime: Singleton ImplementationType: blazejewicz.Blazor.BeforeUnload.BeforeUnload': Cannot consume scoped service 'Microsoft.JSInterop.IJSRuntime' from singleton 'blazejewicz.Blazor.BeforeUnload.BeforeUnload'.)

peterblazejewicz commented 2 years ago

@jmarinl which version of .net you're on at the moment? (note, this one was never run properly on server-backed blazor version)

girlpunk commented 2 years ago

Replacing services.AddBeforeUnload(); with services.AddScoped<BeforeUnload>() removes the exception, however the callback doesn't get run when navigating off the page.

TheCollegedude commented 2 years ago

Hi, has anyone found a solution?

jamesw98 commented 2 years ago

Bump This looks like a perfect solution to what I'm trying to do right now, but am running into the same issue as @girlpunk

IIV21 commented 1 year ago

Has anyone found a solution to using this in a blazor server?

IIV21 commented 1 year ago

The new dotnet 7 updates regarding blazor implement wich implements 2 methods 1 for internal routing (when the user navigates inside the app) 1 for external routing (when the user navigates outside the app, closes the web page or refreshes)

decimvs commented 10 months ago

Starting from ASP .NET 7 you no longer needs to use an external library to do so. You could use the built-in event notifier and component:

More info at MS Docs