question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NavigationLock not working

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am testing new component NavigationLock following this video https://www.youtube.com/watch?v=akffcwNpJiY and built my own Component around NavigationLock:

   public partial class ConfirmNavigation : BaseComponent<ConfirmNavigation>
    {
        [Parameter] public bool IsModified { get; set; }  

        public async Task OnConfirmNavigation(LocationChangingContext context) 
        {
            var confirm = await JSRuntime.InvokeAsync<bool>("window.confirm", "Es gibt nicht gespeicherte Daten. Wollen Sie die Seite wirklich verlassen?");
            Logger.LogInformation(LogEventIdEnum.Navigation.ToEventId(), "Navigation confirmed: {Confirm}, {TargetLocation}", confirm, context.TargetLocation);
            if (!confirm)
            {
                context.PreventNavigation();
            }
        }
    }

and


@inherits BaseComponent<ConfirmNavigation>

    @if (IsModified)
    {
        <NavigationLock OnBeforeInternalNavigation="@OnConfirmNavigation" ConfirmExternalNavigation />
    }

IsModified ist set the following way:

            DtoContext.OnFieldChanged += (sender, e) =>
            {
                var CanSave = DtoContext.Validate();
                IsModified = true;
                StateHasChanged();
            };

Now I enter only one char in input field which is recognised in OnFieldChanged Event. But when I press another link or page reload in browser, NavigationLock is not triggered. With some logging I could verify that IsModified is set to true.

Expected Behavior

NavogationLock Event OnConfirmNavigation ist called and user gets prompted.

Steps To Reproduce

See Bug description

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

It looks like that it works in Debug, and sometimes I observed that it works when Component has been triggered at once, or by just enter a char and then hit <TAB>. Browser is actual version of edge

asp net core 7.0 Visual Studio Version 17.4.1

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
digitalsigicommented, Nov 28, 2022

Ok, the issue is within large project. I will try to extract the necessary parts. Please give me some time to do that.

L.G. Josef Bogad Von meinem iPhone gesendet

Am 28.11.2022 um 18:39 schrieb msftbot[bot] @.***>:

Hi @digitalsigihttps://github.com/digitalsigi. We have added the “Needs: Author Feedback” label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

— Reply to this email directly, view it on GitHubhttps://github.com/dotnet/aspnetcore/issues/45316#issuecomment-1329486319, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABGQGKP22ED7OMZVFQ6ONB3WKTU4HANCNFSM6AAAAAASNOHMGI. You are receiving this because you were mentioned.Message ID: @.***>

0reactions
msftbot[bot]commented, Jan 16, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor - <NavigationLock ConfirmExternalNavigation is not ...
Blazor - <NavigationLock ConfirmExternalNavigation is not reading the latest property value ... And then in my HandleValidSubmitAsync I call (the ...
Read more >
Controlling and Preventing Navigation Events in Blazor Using ...
This blog post looks at NavigationLock: how to implement it, how it works and pitfalls to avoid when using it!
Read more >
Blazor's New LocationChanging Events in .NET 7
With the NavigationLock component, you can block your users from leaving your application when they have unsaved changes for both internal and ...
Read more >
ASP.NET Core Blazor routing and navigation
Learn how to manage Blazor app request routing and how to use the Navigation Manager and NavLink component for navigation.
Read more >
Dual display opening to wrong folder (was: Navigation ...
Hello. I upgraded to Version 12.9 x64 (Pro edition) from version 11, run since 2014, yesterday (Windows 7). I can't get Navigation Lock...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found