protected override void BuildRenderTree(RenderTreeBuilder builder) { if (!CanHandleRoute(RouteContext)) { Logger.LogInformation($"[{Segments}]: No match. Bypassing route"); return; } MetalRouteContext nextcontext = RouteContext.MoveCapturedToParent(this, _segmentCollection); Logger.LogInformation($"[{Segments}]: Match. Handling route"); Logger.LogInformation($"[{Segments}]: New Context: {nextcontext}"); builder.OpenRegion(0); if (Layout is not null) { builder.OpenComponent <LayoutView>(0); builder.AddAttribute(1, "Layout", Layout); builder.AddAttribute(2, "ChildContent", ChildContent(nextcontext)); builder.CloseComponent(); } else { builder.AddContent(0, ChildContent(nextcontext)); } builder.CloseRegion(); _selfHandledRoute = true; }
internal void Refresh(bool isNavigationIntercepted, bool skipUnhandled = false) { Assumes.Present(NavigationManager); Assumes.NotNull(_locationAbsolute); var locationPath = NavigationManager.ToBaseRelativePath(_locationAbsolute); var context = MetalRouteContext.FromBaseRelativePath(this, locationPath); Logger.LogDebug("Attempting to navigate using defined routes in response to path '{Path}' with base '{Base}' and intercepted '{Intercepted}'", locationPath, _baseUri, isNavigationIntercepted); Assumes.NotNull(Routes); _renderHandle.Render(Routes(context)); if (HandledRoute) { Reset(); return; } if (skipUnhandled) { return; } OnUnhandled(isNavigationIntercepted, locationPath); }
private bool CanHandleRoute(MetalRouteContext context) { int segmentCount = _segmentCollection.Count(); Logger.LogDebug($"[{Segments}]: Count={segmentCount}"); IEnumerable <string> capturedSegments = RouteContext.CurrentSegments.Take(segmentCount); Logger.LogDebug($"[{Segments}]: Captured Segments: {capturedSegments.JoinPath()}"); return(capturedSegments.SequenceEqual(_segmentCollection)); }