Skip to content

Commit 9aee608

Browse files
committed
Revert "removed IRoutingStateProvider from Router (#49083)"
This reverts commit 541b49e.
1 parent 8940e99 commit 9aee608

File tree

1 file changed

+14
-0
lines changed
  • src/Components/Components/src/Routing

1 file changed

+14
-0
lines changed

src/Components/Components/src/Routing/Router.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Runtime.ExceptionServices;
99
using Microsoft.AspNetCore.Components.HotReload;
1010
using Microsoft.Extensions.Logging;
11+
using Microsoft.Extensions.DependencyInjection;
1112

1213
namespace Microsoft.AspNetCore.Components.Routing;
1314

@@ -47,6 +48,8 @@ static readonly IReadOnlyDictionary<string, object> _emptyParametersDictionary
4748

4849
[Inject] IServiceProvider ServiceProvider { get; set; }
4950

51+
private IRoutingStateProvider? RoutingStateProvider { get; set; }
52+
5053
/// <summary>
5154
/// Gets or sets the assembly that should be searched for components matching the URI.
5255
/// </summary>
@@ -101,6 +104,7 @@ public void Attach(RenderHandle renderHandle)
101104
_baseUri = NavigationManager.BaseUri;
102105
_locationAbsolute = NavigationManager.Uri;
103106
NavigationManager.LocationChanged += OnLocationChanged;
107+
RoutingStateProvider = ServiceProvider.GetService<IRoutingStateProvider>();
104108

105109
if (HotReloadManager.Default.MetadataUpdateSupported)
106110
{
@@ -197,6 +201,16 @@ internal virtual void Refresh(bool isNavigationIntercepted)
197201
var relativePath = NavigationManager.ToBaseRelativePath(_locationAbsolute);
198202
var locationPath = TrimQueryOrHash(relativePath);
199203

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+
200214
RefreshRouteTable();
201215

202216
var context = new RouteContext($"/{locationPath}");

0 commit comments

Comments
 (0)