Provide a component instance capture in RouteView (aka new RouteView.Instance property)
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
_No response_
### Describe the solution you'd like
`DynamicComponent` already has the `Instance` property, enabling access to the rendered component instance.
Is there anything against having such feature in `RazorView` component as well?
Code modification proposal would be:
```csharp
// src/Components/Components/src/RouteView.cs
public class RouteView : IComponent
{
+ ///
+ /// Gets rendered component instance.
+ ///
+ public object? Instance { get; private set; }
// (...)
private void RenderPageWithParameters(RenderTreeBuilder builder)
{
builder.OpenComponent(0, RouteData.PageType);
// (...)
+ builder.AddComponentReferenceCapture(2, component => Instance = component);
builder.CloseComponent();
}
}
```
### Additional context
In my case, I need to access the rendered component instance after all parameters were set (for our centralized state preservation implementation).
Creating my own router is a possibility, but I'll need to fallback to reflection to mimic today's RouteView behavior (e.g.: the `QueryParameterValueSupplier` is internal and my approach will not be not future-safe).
If suggestion approved, I can provide a pull request.
Contributor guide
Assessment
This issue has not been assessed yet.