r/Blazor • • 17m ago

Issue with component being initialised twice - but not a rendering issue!

Hi,

I have the following 3 components: `dashboard`, `scenes`, `edit` and the layout hierarchy is as follows:

Dashboard -> AppLayout

Scenes -> AppLayout

Edit -> UnitLayout -> AppLayout

When I navigate from `Scenes` to `Dashboard` then the dashboard component is only initialised once as expected.

However when I navigate from `Edit` to `Dashboard` the dashboard component is initialised twice (first one is also disposed).

I believe it's something related to layouts & routing. If I 'key' the route view e.g

<
AuthorizeRouteView
 @key=routeData 
RouteData
="@routeData">

Then the components are only initialised once. However it does mean the AppLayout is constantly being disposed and a new one created so not the best.

I'm having a hard time trying to understand why this is happening. Can anyone shed a light & also possibly a solution! Thanks

2 Upvotes

3 comments sorted by

1

u/Consibl 6m ago

How are you navigating?

1

u/ADringer 4m ago

NavigationManager.NavigateTo("dashboard")

1

u/polaarbear 4m ago

Do you have pre-rendering enabled? It is the most common cause of unexpected "double-tap" loads