Toolbelt.Blazor.ViewTransition 2.0.0

dotnet add package Toolbelt.Blazor.ViewTransition --version 2.0.0
                    
NuGet\Install-Package Toolbelt.Blazor.ViewTransition -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Toolbelt.Blazor.ViewTransition" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Toolbelt.Blazor.ViewTransition" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Toolbelt.Blazor.ViewTransition" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Toolbelt.Blazor.ViewTransition --version 2.0.0
                    
#r "nuget: Toolbelt.Blazor.ViewTransition, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Toolbelt.Blazor.ViewTransition@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Toolbelt.Blazor.ViewTransition&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Toolbelt.Blazor.ViewTransition&version=2.0.0
                    
Install as a Cake Tool

Blazor View Transition NuGet Package

📝 Summary

A router component and a service that makes your Blazor apps have pretty animated transition effects between pages with the View Transitions API.

alternate text is missing from this package README image

🚀 Quick Start

  1. Add this package to your project like this.
dotnet add package Toolbelt.Blazor.ViewTransition
  1. Open Toolbelt.Blazor.ViewTransition namespace in the _Imports.razor file.
@* This is "_Imports.razor" *@
...
@using Toolbelt.Blazor.ViewTransition
  1. Replace a router component to use the ViewTransitionRouter.
@** App.razor **@

@** Replcae the <Router> component to the <ViewTransitionRouter> **@
<ViewTransitionRouter AppAssembly="@typeof(App).Assembly">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="typeof(MainLayout)" />
        <FocusOnNavigate RouteData="@routeData" Selector="[autofocus]" />
    </Found>
    <NotFound>
        <PageTitle>Not found</PageTitle>
        <LayoutView Layout="typeof(MainLayout)">
            <p role="alert">Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</ViewTransitionRouter>
  1. That's all. You will see the default cross-fade transition effect when you move between pages!

alternate text is missing from this package README image

🛠️ Customize the transition effect

  1. Specify the same view-transition-name CSS attribute value for elements that should be transitioned as the same individual element across pages.

alternate text is missing from this package README image

  1. Then, you will see the elements are transitioned as the same individual element across pages!

alternate text is missing from this package README image

These transition effects are implemented by web browser's "View Transion" API. For more details about View Transition API, see MDN web docs and Chrome for Developers docs.

Important
The "View Transition" API is an experimental technology when this library is released. Please check the Browser compatibility table carefully before using this in production.

🛠️ Customize the base router component

The ViewTransitionRouter component is a wrapper component of the Microsoft.AspNetCore.Components.Routing.Router component. You can customize the base router component, such as LazyAssemblyLoadableRouter, by using the TypeOfRouter parameter.

<ViewTransitionRouter ... TypeOfRouter="typeof(LazyAssemblyLoadableRouter)">
    ...
</ViewTransitionRouter>

⚙️ Use the "ViewTransition" service

You can use the IViewTransition service instead of the ViewTransitionRouter component to control the transition effect manually.

  1. Add the ViewTransition service to your Blazor app's DI container.
// Program.cs
...
using Toolbelt.Blazor.Extensions.DependencyInjection; // 👈 Add this line.

var builder = WebAssemblyHostBuilder.CreateDefault(args);
...
builder.Services.AddViewTransition(); // 👈 Add this line.
...
  1. Inject the IViewTransition service to your Blazor component, and surround the DOM modification code you want to apply the transition effect by calling the BeginAsync() and EndAsync() methods. The following example shows how to re-implement the ViewTransitionRouter component yourself.
@inject IViewTransition ViewTransition

<Router AppAssembly="@typeof(App).Assembly" OnNavigateAsync="OnNavigateAsync">
    ...
</Router>

@code
{
    private async Task OnNavigateAsync()
    {
        await this.ViewTransition.BeginAsync();
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await this.ViewTransition.EndAsync();
    }
}

🛠️ JavaScript file cache busting

This library includes and uses a JavaScript file to access the browser's View Transition API. When you update this library to a newer version, the browser may use the cached previous version of the JavaScript file, leading to unexpected behavior. To prevent this issue, the library appends a version query string to the JavaScript file URL when loading it.

.NET 8 and 9

A version query string will always be appended to this library's JavaScript file URL regardless of the Blazor hosting model you are using.

.NET 10 or later

By default, a version query string will be appended to the JavaScript file URL that this library loads. If you want to disable appending a version query string to the JavaScript file URL, you can do so by setting the TOOLBELT_BLAZOR_VIEWTRANSITION_JSCACHEBUSTING environment variable to 0.

// Program.cs
...
// 👇 Add this line to disable appending a version query string for this library's JavaScript file.
Environment.SetEnvironmentVariable("TOOLBELT_BLAZOR_VIEWTRANSITION_JSCACHEBUSTING", "0");

var builder = WebApplication.CreateBuilder(args);
...

However, when you publish a .NET 10 Blazor WebAssembly app, a version query string will always be appended to the JavaScript file URL regardless of the TOOLBELT_BLAZOR_VIEWTRANSITION_JSCACHEBUSTING environment variable setting. The reason is that published Blazor WebAssembly standalone apps don't include import map entries for JavaScript files from NuGet packages. If you want to avoid appending a version query string to the JavaScript file URL in published Blazor WebAssembly apps, you need to set the ToolbeltBlazorViewTransitionJavaScriptCacheBusting MSBuild property to false in the project file of the Blazor WebAssembly app, like this:

<PropertyGroup>
  <ToolbeltBlazorViewTransitionJavaScriptCacheBusting>false</ToolbeltBlazorViewTransitionJavaScriptCacheBusting>
</PropertyGroup>

Why do we append a version query string to the JavaScript file URL regardless of whether the import map is available or not?

We know that .NET 9 or later allows us to use import maps to import JavaScript files with a fingerprint in their file names. Therefore, in .NET 9 or later Blazor apps, you may want to avoid appending a version query string to the JavaScript file URL that this library loads.

However, we recommend keeping the default behavior of appending a version query string to the JavaScript file URL. The reason is that published Blazor WebAssembly standalone apps don't include import map entries for JavaScript files from NuGet packages. This inconsistent behavior between development and production environments and hosting models may lead to unexpected issues that are hard to diagnose, particularly in AutoRender mode apps.

🎉 Release Note

Release notes

📢 License

Mozilla Public License Version 2.0

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Toolbelt.Blazor.ViewTransition:

Package Downloads
VaultForce.SharedClient

shared resources

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 652 1/2/2026
1.0.4 13,437 2/26/2025
1.0.3 11,068 11/16/2023
1.0.2 185 10/29/2023
1.0.1 152 10/28/2023

v.2.0.0
- Update: Added support for .NET 10, and dropped support for .NET 7 or earlier.
- Improve: Removed the dependency on the Toolbelt.Blazor.GetProperty.Script NuGet package for .NET 10 or later projects.
- Improve: Better support for controlling JavaScript caching strategies on .NET 10 or later projects.


To see all the change logs, please visit the following URL.
- https://github.com/jsakamoto/Toolbelt.Blazor.ViewTransition/blob/main/RELEASE-NOTES.txt