mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.25k stars 144 forks source link

How to properly use RoutingMiddleware? #223

Closed uhfath closed 2 years ago

uhfath commented 2 years ago

If I'm not mistaking this class is responsible for navigating through actions and monitoring current navigation state. If so, than using [Inject] private IState<RoutingState> RoutingState { get; set; } should give me current navigation state. However, when used like this:

protected override void OnParametersSet()
{
    base.OnParametersSet();

    Console.WriteLine("PARAM STATE: {0}", RoutingState.Value.Uri);
    Console.WriteLine("PARAM MANAGER: {0}", NavigationManager.Uri);
}

protected override async Task OnParametersSetAsync()
{
    await base.OnParametersSetAsync();

    Console.WriteLine("ASYNC PARAM STATE: {0}", RoutingState.Value.Uri);
    Console.WriteLine("ASYNC PARAM MANAGER: {0}", NavigationManager.Uri);
}

protected override void OnInitialized()
{
    base.OnInitialized();

    Console.WriteLine("STATE: {0}", RoutingState.Value.Uri);
    Console.WriteLine("MANAGER: {0}", NavigationManager.Uri);
}

protected override async Task OnInitializedAsync()
{
    await base.OnInitializedAsync();

    Console.WriteLine("ASYNC STATE: {0}", RoutingState.Value.Uri);
    Console.WriteLine("ASYNC MANAGER: {0}", NavigationManager.Uri);
}

It gives me this:

STATE: 
MANAGER: http://localhost:40000/SignIn?returnUrl=clients%3Fvalue%3DnewValue%26value_2%3DnewValue_2

ASYNC STATE: 
ASYNC MANAGER: http://localhost:40000/SignIn?returnUrl=clients%3Fvalue%3DnewValue%26value_2%3DnewValue_2

PARAM STATE: 
PARAM MANAGER: http://localhost:40000/SignIn?returnUrl=clients%3Fvalue%3DnewValue%26value_2%3DnewValue_2

ASYNC PARAM STATE: 
ASYNC PARAM MANAGER: http://localhost:40000/SignIn?returnUrl=clients%3Fvalue%3DnewValue%26value_2%3DnewValue_2

Shouldn't they be equal? This is how Fluxor is setup:

services
    .AddFluxor(opts =>
     {
         opts.ScanAssemblies(typeof(FluxorServiceExtensions).Assembly, fluxorAssemblyTypes
            .Select(t => t.GetTypeInfo().Assembly)
            .Distinct()
            .ToArray());
#if DEBUG
         opts.UseReduxDevTools();
#endif
         opts.UseRouting();
     });
mrpmorris commented 2 years ago

By any chance, is this an ASP.NET hosted WASM app written in .NETCore 3,1 with server-side rendering enabled?

Are you seeing output from server-side rendering? Fluxor isn't active until after first render.

uhfath commented 2 years ago

That's a NET 5 Blazor WASM standalone project.

mrpmorris commented 2 years ago

Can you create a repo I can clone?

uhfath commented 2 years ago

Sure, here you go.

I think this is the same issue as was discussed in #226 The state is reduced when you navigate to the page, but not when opening it directly since the actions are queued. You can see that in the console.

mrpmorris commented 2 years ago

Sorry to have taken so long to come back to you, this one slipped my attention.

I've tried your repo and the output in the console is correct.

STATE: http://localhost:13006/counter
MANAGER: http://localhost:13006/counter
ASYNC STATE: http://localhost:13006/counter
ASYNC MANAGER: http://localhost:13006/counter
PARAM STATE: http://localhost:13006/counter
PARAM MANAGER: http://localhost:13006/counter
ASYNC PARAM STATE: http://localhost:13006/counter
ASYNC PARAM MANAGER: http://localhost:13006/counter

I'll close this for now. If you have more information for me then reply here and I will reopen it.