mrpmorris / Fluxor

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

Question: how to listen on the GoAction? #307

Closed StefH closed 2 years ago

StefH commented 2 years ago

I see that the GoAction is used for navigation in a Blazor App.

How can I listen to this action and then update some text on the page?

I made a feature:

public class GoActionFeature : Feature<GoAction>
{
    public override string GetName()
    {
        return "GoAction";
    }

    protected override GoAction GetInitialState()
    {
        return new GoAction("/", false);
    }
}

And a new component:

@using Fluxor.Blazor.Web.Middlewares.Routing

@inherits FluxorComponent

@inject IState<GoAction> GoActionState

CurrentPage = @GoActionState.Value.NewUri

And this component is included on the mainpage:

@inherits LayoutComponentBase

<div class="page">
    <div class="sidebar">
        <NavMenu />
    </div>

    <main>
        <div class="top-row px-4">
            <ShowPage />
        </div>

        <article class="content px-4">
            @Body
        </article>
    </main>
</div>

But the text is not changed?

mrpmorris commented 2 years ago
<h1>@RoutingState.State.Uri</h1>

@code {
  [inject] private IState<RoutingState> RoutingState { get; set; }
}