From 37d74780798e83490dd226c8cb8b8eaa35e2b433 Mon Sep 17 00:00:00 2001 From: Peter Morris Date: Wed, 3 Nov 2021 21:15:26 +0000 Subject: [PATCH] Add ForceLoad to GoAction #178 (#227) --- Docs/releases.md | 3 ++- Source/Fluxor.Blazor.Web/Middlewares/Routing/Effects.cs | 7 ++++--- Source/Fluxor.Blazor.Web/Middlewares/Routing/GoAction.cs | 7 ++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Docs/releases.md b/Docs/releases.md index e57d0452..aad13099 100644 --- a/Docs/releases.md +++ b/Docs/releases.md @@ -3,7 +3,8 @@ ## New in 4.2 * New `[FeatureState]` attribute to avoid having to create `Feature` descendant classes. ([#204](https://github.com/mrpmorris/Fluxor/issues/204)) * Add `FluxorOptions.ScanTypes` to allow scanning of specified classes. ([#214](https://github.com/mrpmorris/Fluxor/issues/214)) - * Make `FluxorComponent` and `FluxorLayout` abstract ([#217](https://github.com/mrpmorris/Fluxor/issues/217)) + * Make `FluxorComponent` and `FluxorLayout` abstract. ([#217](https://github.com/mrpmorris/Fluxor/issues/217)) + * Add `ForceLoad` property to `GoAction`. ([#178](https://github.com/mrpmorris/Fluxor/issues/178)) ## New in 4.1 * Allow custom control over JSON serialisation in Redux Dev Tools - see diff --git a/Source/Fluxor.Blazor.Web/Middlewares/Routing/Effects.cs b/Source/Fluxor.Blazor.Web/Middlewares/Routing/Effects.cs index a34da8e2..136c69c6 100644 --- a/Source/Fluxor.Blazor.Web/Middlewares/Routing/Effects.cs +++ b/Source/Fluxor.Blazor.Web/Middlewares/Routing/Effects.cs @@ -17,10 +17,11 @@ public Effects(NavigationManager navigationManager) public Task HandleGoActionAsync(GoAction action, IDispatcher dispatcher) { Uri fullUri = NavigationManager.ToAbsoluteUri(action.NewUri); - if (fullUri.ToString() != NavigationManager.Uri) + if (fullUri.ToString() != NavigationManager.Uri || action.ForceLoad) { - // Only navigate if we are not already at the URI specified - NavigationManager.NavigateTo(action.NewUri); + // Only navigate if we are not already at the URI specified, + // or if we have been told to do a proper page reload (ForceLoad) + NavigationManager.NavigateTo(action.NewUri, action.ForceLoad); } return Task.CompletedTask; } diff --git a/Source/Fluxor.Blazor.Web/Middlewares/Routing/GoAction.cs b/Source/Fluxor.Blazor.Web/Middlewares/Routing/GoAction.cs index 1a2ae99b..be1986d5 100644 --- a/Source/Fluxor.Blazor.Web/Middlewares/Routing/GoAction.cs +++ b/Source/Fluxor.Blazor.Web/Middlewares/Routing/GoAction.cs @@ -13,11 +13,16 @@ public class GoAction /// public string NewUri { get; } + /// + /// When true forces a real browser navigation and page reload + /// + public bool ForceLoad { get; } + /// /// Creates a new instance of the action /// /// - public GoAction(string newUri) + public GoAction(string newUri, bool forceLoad = false) { NewUri = newUri; }