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: aspnetcore/blazor/fundamentals/routing.md
+126-1Lines changed: 126 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -571,7 +571,25 @@ Slashes and segments of the captured path are decoded. For a route template of `
571
571
572
572
Use <xref:Microsoft.AspNetCore.Components.NavigationManager> to manage URIs and navigation in C# code. <xref:Microsoft.AspNetCore.Components.NavigationManager> provides the event and methods shown in the following table.
573
573
574
-
:::moniker range=">= aspnetcore-8.0"
574
+
:::moniker range=">= aspnetcore-10.0"
575
+
576
+
<!-- UPDATE 10.0 - API doc cross-links -->
577
+
578
+
Member | Description
579
+
--- | ---
580
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.Uri> | Gets the current absolute URI.
581
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.BaseUri> | Gets the base URI (with a trailing slash) that can be prepended to relative URI paths to produce an absolute URI. Typically, <xref:Microsoft.AspNetCore.Components.NavigationManager.BaseUri> corresponds to the `href` attribute on the document's `<base>` element ([location of `<head>` content](xref:blazor/project-structure#location-of-head-and-body-content)).
582
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.NavigateTo%2A> | Navigates to the specified URI. If `forceLoad` is `false`:<ul><li>And enhanced navigation is available at the current URL, Blazor's enhanced navigation is activated.</li><li>Otherwise, Blazor performs a full-page reload for the requested URL.</li></ul>If `forceLoad` is `true`:<ul><li>Client-side routing is bypassed.</li><li>The browser is forced to load the new page from the server, whether or not the URI is normally handled by the client-side interactive router.</li></ul><p>For more information, see the [Enhanced navigation and form handling](#enhanced-navigation-and-form-handling) section.</p><p>If `replace` is `true`, the current URI in the browser history is replaced instead of pushing a new URI onto the history stack.</p>
583
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.LocationChanged> | An event that fires when the navigation location has changed. For more information, see the [Location changes](#location-changes) section.
584
+
`NotFound` | Called to handle scenarios where a requested resource isn't found. For more information, see the [Not Found responses](#not-found-responses) section.
585
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri%2A> | Converts a relative URI into an absolute URI.
586
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.ToBaseRelativePath%2A> | Based on the app's base URI, converts an absolute URI into a URI relative to the base URI prefix. For an example, see the [Produce a URI relative to the base URI prefix](#produce-a-uri-relative-to-the-base-uri-prefix) section.
587
+
[`RegisterLocationChangingHandler`](#handleprevent-location-changes) | Registers a handler to process incoming navigation events. Calling <xref:Microsoft.AspNetCore.Components.NavigationManager.NavigateTo%2A> always invokes the handler.
588
+
<xref:Microsoft.AspNetCore.Components.NavigationManagerExtensions.GetUriWithQueryParameter%2A> | Returns a URI constructed by updating <xref:Microsoft.AspNetCore.Components.NavigationManager.Uri?displayProperty=nameWithType> with a single parameter added, updated, or removed. For more information, see the [Query strings](#query-strings) section.
For more information on component disposal, see <xref:blazor/components/component-disposal>.
686
704
705
+
:::moniker range=">= aspnetcore-10.0"
706
+
707
+
## Not Found responses
708
+
709
+
<!-- UPDATE 10.0 - API doc cross-links -->
710
+
711
+
*In ASP.NET Core 10.0 Preview 4, Not Found responses are only available for static SSR and global interactive rendering. Per-page/component rendering support is planned for Preview 5 in June, 2025.*
712
+
713
+
<xref:Microsoft.AspNetCore.Components.NavigationManager> provides a `NotFound` method to handle scenarios where a requested resource isn't found during static server-side rendering (static SSR) or global interactive rendering:
714
+
715
+
***Static SSR**: Calling `NotFound` sets the HTTP status code to 404.
716
+
***Streaming rendering**: Throws an exception if the response has already started.
717
+
***Interactive rendering**: Signals the Blazor router ([`Router` component](xref:blazor/fundamentals/routing#route-templates)) to render Not Found content.
718
+
719
+
When a component is rendered statically (static SSR) and `NavigationManager.NotFound` is called, the 404 status code is set on the response:
720
+
721
+
```razor
722
+
@page "/render-not-found-ssr"
723
+
@inject NavigationManager Navigation
724
+
725
+
@code {
726
+
protected override void OnInitialized()
727
+
{
728
+
Navigation.NotFound();
729
+
}
730
+
}
731
+
```
732
+
733
+
Two approaches for providing Not Found content for global interactive rendering:
734
+
735
+
* Use a Not Found page (Razor component).
736
+
* Specify Not Found content in the [`Router` component's](xref:blazor/fundamentals/routing#route-templates)<xref:Microsoft.AspNetCore.Components.Routing.Router.NotFound%2A> property (`<NotFound>...</NotFound>` markup or by setting the `NotFound` parameter to a render fragment in C# code).
737
+
738
+
The following example uses a Not Found page (`NotFoundPage` component) to render Not Found content.
739
+
740
+
`NotFoundPage.razor`:
741
+
742
+
```razor
743
+
<h1>Not Found</h1>
744
+
745
+
<p>Sorry! Nothing to show.</p>
746
+
```
747
+
748
+
Specify the `NotFoundPage` component to the `Router` component in `Routes.razor`. You might need to specify the component's namespace with an [`@using`](xref:mvc/views/razor#using) directive either at the top of the `Routes.razor` file or in an [`_Imports.razor` file](xref:blazor/components/index#component-name-class-name-and-namespace).
749
+
750
+
```razor
751
+
<Router ...>
752
+
<Found ...>
753
+
...
754
+
</Found>
755
+
<NotFound>
756
+
<NotFoundPage />
757
+
</NotFound>
758
+
</Router>
759
+
```
760
+
761
+
When a component is rendered with a global interactive render mode, calling `NotFound` signals the Blazor router to render Not Found content, which is the `NotFoundPage` component:
762
+
763
+
```razor
764
+
@page "/render-not-found-interactive"
765
+
@inject NavigationManager Navigation
766
+
767
+
@if (RendererInfo.IsInteractive)
768
+
{
769
+
<button @onclick="TriggerNotFound">Trigger Not Found</button>
770
+
}
771
+
772
+
@code {
773
+
private void TriggerNotFound()
774
+
{
775
+
Navigation.NotFound();
776
+
}
777
+
}
778
+
```
779
+
780
+
You can use the `OnNotFound` event for notifications when `NotFound` is invoked. The following example uses a render fragment (<xref:Microsoft.AspNetCore.Components.RenderFragment>) to render the Not Found content.
# ASP.NET Core Blazor WebAssembly browser developer tools diagnostics
@@ -40,10 +40,12 @@ The MSBuild properties in the following table enable profiler integration.
40
40
Property | Default | Set value to… | Description
41
41
--- | :---: | :---: | ---
42
42
`<WasmProfilers>` | No value | `browser` | Mono profilers to use. Potential values are "`browser`" and "`log`". To use both, separate the values with a semicolon. The `browser` profiler enables integration with the browser's developer tools profiler.
`<WasmNativeDebugSymbols>` | `true` | `true` | Enables building with native debug symbols.
45
45
46
-
Enabling profilers has negative size and performance impact, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:BlazorSampleProfilingEnabled=true` (.NET CLI) or `<BlazorSampleProfilingEnabled>true</BlazorSampleProfilingEnabled>` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names.
46
+
Setting the [`Timing-Allow-Origin` HTTP header](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Timing-Allow-Origin) allows for more precise time measurements.
47
+
48
+
Enabling profilers has negative size and performance impacts, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:BlazorSampleProfilingEnabled=true` (.NET CLI) or `<BlazorSampleProfilingEnabled>true</BlazorSampleProfilingEnabled>` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names.
47
49
48
50
In the app's project file (`.csproj`):
49
51
@@ -61,9 +63,9 @@ Alternatively, enable features when the app is built with the .NET CLI. The foll
Setting WebAssembly profilers with `<WasmProfilers>browser;</WasmProfilers>` doesn't require AOT.
66
+
Setting WebAssembly profilers with `<WasmProfilers>` doesn't require [ahead-of-time (AOT) compilation](xref:blazor/tooling/webassembly).
65
67
66
-
The browser developer tools profiler can be used with AOT (`<RunAOTCompilation>`/`<RunAOTCompilationAfterBuild>` set to `true`) and without WebAssembly profilers (`<WasmProfilers>browser;</WasmProfilers>` removed from the preceding property group).
68
+
The browser developer tools profiler can be used with AOT (`<RunAOTCompilation>`/`<RunAOTCompilationAfterBuild>` set to `true`) and without WebAssembly profilers (`<WasmProfilers>` removed).
67
69
68
70
To see AOT method names in the developer tools console, install [DWARF chrome extension](https://chromewebstore.google.com/detail/cc++-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb).
69
71
@@ -92,7 +94,6 @@ Permissiable `{FILTER}` placeholder values are shown in the following table.
92
94
Filter | Description
93
95
--- | ---
94
96
`all` | All assemblies
95
-
`none` | No assemblies
96
97
`program` | Entry point assembly
97
98
`{ASSEMBLY}` | Specifies an assembly (`{ASSEMBLY}`)
98
99
`M:Type:{METHOD}` | Specifies a method (`{METHOD}`)
@@ -107,18 +108,6 @@ In the following example, profiled methods are filtered to the app's namespace,
In the project file (`.csproj`), use the `<WasmProfilers>` property set to `browser` to enable integration with the Mono profiler. Currently, only "`browser`" is supported. The `browser` profiler enables integration with the browser's developer tools profiler.
113
-
114
-
```xml
115
-
<PropertyGroup>
116
-
<WasmProfilers>browser</WasmProfilers>
117
-
</PropertyGroup>
118
-
```
119
-
120
-
The [`Timing-Allow-Origin` HTTP header](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Timing-Allow-Origin) allows for more precise time measurements.
121
-
122
111
## Additional resources
123
112
124
113
*[What diagnostic tools are available in .NET Core?](/dotnet/core/diagnostics/)
Copy file name to clipboardExpand all lines: aspnetcore/blazor/performance/webassembly-event-pipe-diagnostics.md
+22-8Lines changed: 22 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,11 +41,25 @@ The MSBuild properties in the following table enable profiler integration.
41
41
42
42
Property | Default | Set value to… | Description
43
43
--- | :---: | :---: | ---
44
-
`<WasmPerfTracing>` | `false` | `true` | Controls diagnostic server tracing.
45
-
`<MetricsSupport>` | `false` | `true` | Controls `System.Diagnostics.Metrics` support. For more information, see the [`System.Diagnostics.Metrics` namespace](/dotnet/api/system.diagnostics.metrics).
46
-
`<EventSourceSupport>` | `false`| `true` | Controls `EventPipe` support. For more information, see [Diagnostics and instrumentation: Observability and telemetry](/dotnet/core/deploying/native-aot/diagnostics#observability-and-telemetry).
47
-
48
-
Enabling profilers has negative size and performance impact, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:BlazorSampleProfilingEnabled=true` (.NET CLI) or `<BlazorSampleProfilingEnabled>true</BlazorSampleProfilingEnabled>` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names.
44
+
`<WasmPerfTracing>` | `false` | `true` | Enables support for WebAssembly performance tracing.
45
+
`<WasmPerfInstrumentation>` | No value | See table† | Enables instrumentation necessary for the sampling profiler. The property follows the :::no-loc text="callspec"::: syntax. †For permissible values, see the following table.
46
+
`<MetricsSupport>` | `false` | `true` | Enables `System.Diagnostics.Metrics` support. For more information, see the [`System.Diagnostics.Metrics` namespace](/dotnet/api/system.diagnostics.metrics).
47
+
`<EventSourceSupport>` | `false`| `true` | Enables `EventPipe` support. For more information, see [Diagnostics and instrumentation: Observability and telemetry](/dotnet/core/deploying/native-aot/diagnostics#observability-and-telemetry).
48
+
49
+
The following table describes permissable `<WasmPerfInstrumentation>` values.
50
+
51
+
`<WasmPerfInstrumentation>` value | Description
52
+
--- | ---
53
+
`all` | All assemblies
54
+
`program` | Entry point assembly
55
+
`{ASSEMBLY}` | Specifies an assembly (`{ASSEMBLY}`)
56
+
`M:Type:{METHOD}` | Specifies a method (`{METHOD}`)
57
+
`N:{NAMESPACE}` | Specifies a namespace (`{NAMESPACE}`)
58
+
`T:{TYPE}` | Specifies a type (`{TYPE}`)
59
+
`+EXPR` | Includes expression
60
+
`-EXPR` | Excludes expression
61
+
62
+
Enabling profilers has negative size and performance impacts, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:BlazorSampleProfilingEnabled=true` (.NET CLI) or `<BlazorSampleProfilingEnabled>true</BlazorSampleProfilingEnabled>` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names.
49
63
50
64
In the app's project file (`.csproj`):
51
65
@@ -60,7 +74,7 @@ In the app's project file (`.csproj`):
60
74
Alternatively, enable features when the app is built with the .NET CLI. The following options passed to the `dotnet build` command mirror the preceding MS Build property configuration:
The [`Timing-Allow-Origin` HTTP header](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Timing-Allow-Origin) allows for more precise time measurements.
@@ -69,13 +83,13 @@ The [`Timing-Allow-Origin` HTTP header](https://developer.mozilla.org/docs/Web/H
69
83
70
84
[EventPipe](/dotnet/core/diagnostics/eventpipe) is a runtime component used to collect tracing data, similar to [ETW](/windows/win32/etw/event-tracing-portal) and [perf_events](https://wikipedia.org/wiki/Perf_%28Linux%29).
71
85
72
-
Use the `<WasmPerfInstrumentation>` property to enable CPU sampling instrumentation for diagnostic server. This setting isn't necessary for memory dump or counters. **Makes the app execute slower. Only set this to `true` for performance profiling.**
86
+
Use the `<WasmPerfInstrumentation>` property to enable CPU sampling instrumentation for diagnostic server. This setting isn't necessary for memory dump or counters. **Makes the app execute slower. Only enable this for performance profiling.**
73
87
74
88
Enabling profilers has negative size and performance impact, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:BlazorSampleProfilingEnabled=true` (.NET CLI) or `<BlazorSampleProfilingEnabled>true</BlazorSampleProfilingEnabled>` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names.
0 commit comments