You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,9 @@ All notable changes to **bUnit** will be documented in this file. The project ad
6
6
7
7
## [Unreleased]
8
8
9
+
### Added
10
+
- Implemented feature to map route templates to parameters using NavigationManager. This allows parameters to be set based on the route template when navigating to a new location. Reported by [JamesNK](https://github.com/JamesNK) in [#1580](https://github.com/bUnit-dev/bUnit/issues/1580). By [@linkdotnet](https://github.com/linkdotnet).
Copy file name to clipboardExpand all lines: docs/site/docs/providing-input/passing-parameters-to-components.md
+35
Original file line number
Diff line number
Diff line change
@@ -501,6 +501,41 @@ A simple example of how to test a component that receives parameters from the qu
501
501
}
502
502
```
503
503
504
+
## Setting parameters via routing
505
+
In Blazor, components can receive parameters via routing. This is particularly useful for passing data to components based on the URL. To enable this, the component parameters need to be annotated with the `[Parameter]` attribute and the `@page` directive (or `RouteAttribute` in code behind files).
506
+
507
+
An example component that receives parameters via routing:
508
+
509
+
```razor
510
+
@page "/counter/{initialCount:int}"
511
+
512
+
<p>Count: @InitialCount</p>
513
+
514
+
@code {
515
+
[Parameter]
516
+
public int InitialCount { get; set; }
517
+
}
518
+
```
519
+
520
+
To test a component that receives parameters via routing, set the parameters using the `NavigationManager`:
521
+
522
+
```razor
523
+
@inherits TestContext
524
+
525
+
@code {
526
+
[Fact]
527
+
public void Component_receives_parameters_from_route()
528
+
{
529
+
var cut = RenderComponent<ExampleComponent>();
530
+
var navigationManager = Services.GetRequiredService<NavigationManager>();
0 commit comments