M. Akar
M. Akar

Reputation: 1865

How to pass generic parameter though NavLink in Blazor?

I have a generic component that expects a generic type parameter to be passed. Componenet is as follows:

@page "/topicgrid"
@typeparam TDataModel
<h1>Title</h1>

The code-behind class is as follows:

public partial class TopicGrid<TDataModel> : ComponentBase
{
}

I can use this component as follows:

<TopicGrid TDataModel="SomeTopicModel" /> // SomeTopicModel is a class

However, I need to create this component through the NavLink component. NavLink only wants to know the route of the component, nothing else. How could I achieve this?

<NavLink class="nav-link" href="topicgrid">
    Topic Grid
</NavLink>

Upvotes: 0

Views: 1618

Answers (1)

Julio Cachay
Julio Cachay

Reputation: 830

You can nest your generic component inside another component whose job is to initialize the parameters that you need to pass.

@page “/topicgrid”
<TopicGrid .../>

Upvotes: 2

Related Questions