|
8 | 8 | using System.Runtime.ExceptionServices;
|
9 | 9 | using Microsoft.AspNetCore.Components.HotReload;
|
10 | 10 | using Microsoft.Extensions.Logging;
|
| 11 | +using Microsoft.Extensions.DependencyInjection; |
11 | 12 |
|
12 | 13 | namespace Microsoft.AspNetCore.Components.Routing;
|
13 | 14 |
|
@@ -47,6 +48,8 @@ static readonly IReadOnlyDictionary<string, object> _emptyParametersDictionary
|
47 | 48 |
|
48 | 49 | [Inject] IServiceProvider ServiceProvider { get; set; }
|
49 | 50 |
|
| 51 | + private IRoutingStateProvider? RoutingStateProvider { get; set; } |
| 52 | + |
50 | 53 | /// <summary>
|
51 | 54 | /// Gets or sets the assembly that should be searched for components matching the URI.
|
52 | 55 | /// </summary>
|
@@ -101,6 +104,7 @@ public void Attach(RenderHandle renderHandle)
|
101 | 104 | _baseUri = NavigationManager.BaseUri;
|
102 | 105 | _locationAbsolute = NavigationManager.Uri;
|
103 | 106 | NavigationManager.LocationChanged += OnLocationChanged;
|
| 107 | + RoutingStateProvider = ServiceProvider.GetService<IRoutingStateProvider>(); |
104 | 108 |
|
105 | 109 | if (HotReloadManager.Default.MetadataUpdateSupported)
|
106 | 110 | {
|
@@ -197,6 +201,16 @@ internal virtual void Refresh(bool isNavigationIntercepted)
|
197 | 201 | var relativePath = NavigationManager.ToBaseRelativePath(_locationAbsolute);
|
198 | 202 | var locationPath = TrimQueryOrHash(relativePath);
|
199 | 203 |
|
| 204 | + // In order to avoid routing twice we check for RouteData |
| 205 | + if (RoutingStateProvider?.RouteData is { } endpointRouteData) |
| 206 | + { |
| 207 | + Log.NavigatingToComponent(_logger, endpointRouteData.PageType, locationPath, _baseUri); |
| 208 | + |
| 209 | + _renderHandle.Render(Found(endpointRouteData)); |
| 210 | + |
| 211 | + return; |
| 212 | + } |
| 213 | + |
200 | 214 | RefreshRouteTable();
|
201 | 215 |
|
202 | 216 | var context = new RouteContext($"/{locationPath}");
|
|
0 commit comments