You can do that in various ways depending on whether ComponentA and ComponentB are both routable components or not.
If ComponentB is a child component of ComponentA; that is, ComponentB, which is not routable, is embedded within ComponentA, you can pass values from ComponentA to ComponentB as Component parameters... The following code snippet creates a parent component and a child component, and demonstrate how to pass values from the parent component to the child component:
Parent.razor
@page "/parent"
<Child Age="age" Country="country" />
@code
{
private int age = 21;
private string country = "Thailand";
}
Child.razor
@ No @page directive here as the child component is not routable @
<p>Country: @Country</p>
@code
{
[Parameter]
Public int Age {get; set;}
[Parameter]
Public string Country {get; set;}
}
As you can see, we pass age and country values from the parent component to it's child component. In real life code, you may pass collections of objects, do various manipulations, etc. The above is a basic outline of how a parent can communicate with it's child and pass it values. The other way around, that is, to pass values from the child component to its parent is done via event delegates.
When both components are Component pages; that is, both are routable, you usually need a mediator object to perform passing values from one component to another.
Suppose you want to redirect your user from the current page, say ComponentA, where he has filled a form with lots of data items, to ComponentB, which gets the data, process it, etc. Here's the code how to navigate from ComponentA to Navigate to ComponentB:
<button type="button" @onclick="ShowList">Show list of women</button>
@code
{
private void ShowList()
{
NavigateManager.NavigateTo("/ComponentB");
}
}
As you can see, the code above redirects the user from one page to another, but how to pass the data ? To achieve this you have to define a service class that can be injected into both components to perform the passing of data from one to another. The following link is to an answer of mine where I speak in details about this mechanism.
Hope this helps...