Blazored / Menu

A JavaScript free menu library for Blazor and Razor Components applications.
https://blazored.github.io/Menu
MIT License
176 stars 32 forks source link

Keep submenu open when navigating to new page #17

Closed digitalsigi closed 4 years ago

digitalsigi commented 4 years ago

Hi Chris, Thx for your work, I use some of your packages and want now to work with menu. I my situation, it seem to be a litte more complicated. To be able to use browse back button with pagination I decided to implement navigation through url, e.g. http//mylongindex/5 goes to page 5. This works fine and even for opening detail views and so on. However with submenus it seems tricky to keep them open when a new page is displayed, because obviously the initial state is closed and thus submenu is closed. Question: How to keep the submenu open across pages?

chrissainty commented 4 years ago

If you're not reloading the whole application, then the state of the menu should be maintained between page changes. Is the whole app reloading when you change pages?

digitalsigi commented 4 years ago

If you're not reloading the whole application, then the state of the menu should be maintained between page changes. Is the whole app reloading when you change pages?

Hmmm, good question, I believe yes, cause I fire navigateto(...). In the meantime I found this https://brianlagunas.com/lets-learn-blazor-managing-state-in-blazor-fail/ which pointed back to your packages. So I guess, I need to maintain the state between pages. I'll dig into this and when I find a solution I'll post it.

chrissainty commented 4 years ago

Using NavigateTo shouldn't cause a page refresh unless you're using the forceReload option. Can you share the code for changing pages?

digitalsigi commented 4 years ago

OK, I think I found the reason: I was playing with non existing pages just to try BlazoredMenu. Consequently I ended up at what is defined in app.razor and this closes - for whatever reason - the menu. As soon as I navigate to existing pages, everything worked as expected. I guess: case closed. This is how my app.razor looks:

<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
        <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
    </Found>
    <NotFound>
        <CascadingAuthenticationState>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Da gibt's leider nichts.</p>
            </LayoutView>
        </CascadingAuthenticationState>
    </NotFound>
</Router>

May be there are better solutions, but in this special case I don't care. Thx for careing.

chrissainty commented 4 years ago

No worries, glad we worked it out.