允许当前和之前的路由存在,以支持页面过渡动画。
Allows current and previous route to exist enabling page transition animations.
Sometimes you need to show transitions between page routes but Blazor, by default, only allows one. This Razor component library provides the ability to remember the last route and allows you to perform transitions out and in, on the old and new route views. You can also use this information to contextually perform different transitions based on the route page types being transitioned.
Install-Package BlazorTransitionableRouteor
dotnet add package BlazorTransitionableRouteAdd reference to _Imports.razor file
@using BlazorTransitionableRouteAdd registrations for the dependency injection framework in Program.cs, for example
builder.Services.AddScoped();Or BlazorTransitionableRoute.DefaultRouteTransitionInvoker if you implement transitions via Blazor code and not via jsInterop.
You will need to change App.razor to use the newly provided TransitionableRoutePrimary/Secondary components
Modify the App.razor file
Modify the App.razor file to take advantage of the transitionable route layouts and view. This means moving the MainLayout to be more explicit in the app router and providing a more container like MyViewLayout as the default layouts. You can see below the simple use of primary and secondary route views. The TransitionableRoutePrimary / Secondary modify the RouteData passed to each inner TransitionableRouteView based on the active state, which is swapped after each navigation to preserve component instances.
Sorry, there's nothing at this address.
Create your own transitiong view
This example code shows the Blazor coded implementation. For jsInterop see the example usage section below.
@inherits TransitionableLayoutComponent
@code {
private string transitioningDirection => Transition.Backwards ? "Up" : "Down";
private string transitioningClass => Transition.FirstRender ? "" : Transition.IntoView
? $"animate__fadeIn{transitioningDirection} animate__faster animate__animated"
: $"animate__fadeOut{transitioningDirection} animate__faster animate__animated";
}Transition parameter is provided by the inherited TransitionableLayoutComponent
Notes on usage
ForgetStateOnTransition to falsewindow.history.back();AuthorizeRouteView then you will have to create you own razor component similar to TransitionableRouteView and consume in the App.razor file. See the 'Example Usage' section below for details.The library provides a simple set of properties to aid you in adding transitions to your projects.
The TransitionableLayoutComponent, which you may inherit, providing
Transition propertiesIntoView - true, if the route should be made visibleBackwards - true, if you want to reverse animations, for instanceFirstRender - true, if you want to stop transitioning because of first loadRouteData reference data you may like to useSwitchedRouteData reference data you may like to useTransitionType a tuple property to allow custom transitions based on what is being transitionedfromType is the previous route PageTypetoType is the active route PageTypeThere is also IRouteTransitionInvoker that you implement when using jsInterop for transitions
InvokeRouteTransitionAsync - provides the Transition parameter and where you invoke JS interop.You can find detailed documentation on example usage here
These demos show examples of the Blazor coded transition option (for the Javascript interop transition option, see the detailed documentation mentioned above).
BlazorTransitionableRouteDemoWasm demo for WebAssembly Apps. see commit for implementation detailsAuthorizeRouteView changes see this commitBlazorTransitionableRouteDemoServer demo for Server Apps. see commit for implementation detailsAuthorizeRouteView changes see this commitTransitionDurationMilliseconds to clear switched route view after transition. Only when ForgetStateOnTransition is set to true.Transition.SwitchedRouteData along with Transition.RouteData to provide means to perform custom transitions. i.e. parent/child views.ForgetStateOnTransition option to reset page state when returning to previous route via navigation.Transition.FirstRenderTransition.BackwardsForgetStateOnTransition configurable to specific page types暂无开放 Issues,或尚未同步最近议题。