@@ -22,6 +22,7 @@ import {ROUTER_SCROLLER, RouterScroller} from './router_scroller';
2222import { ActivatedRoute } from './router_state' ;
2323import { UrlSerializer } from './url_tree' ;
2424import { afterNextNavigation } from './utils/navigations' ;
25+ import { CREATE_VIEW_TRANSITION , createViewTransition } from './utils/view_transition' ;
2526
2627
2728/**
@@ -661,6 +662,16 @@ export function withNavigationErrorHandler(fn: (error: NavigationError) => void)
661662export type ComponentInputBindingFeature =
662663 RouterFeature < RouterFeatureKind . ComponentInputBindingFeature > ;
663664
665+ /**
666+ * A type alias for providers returned by `withViewTransitions` for use with `provideRouter`.
667+ *
668+ * @see {@link withViewTransitions }
669+ * @see {@link provideRouter }
670+ *
671+ * @publicApi
672+ */
673+ export type ViewTransitionsFeature = RouterFeature < RouterFeatureKind . ViewTransitionsFeature > ;
674+
664675/**
665676 * Enables binding information from the `Router` state directly to the inputs of the component in
666677 * `Route` configurations.
@@ -690,6 +701,38 @@ export function withComponentInputBinding(): ComponentInputBindingFeature {
690701 return routerFeature ( RouterFeatureKind . ComponentInputBindingFeature , providers ) ;
691702}
692703
704+ /**
705+ * Enables view transitions in the Router by running the route activation and deactivation inside of
706+ * `document.startViewTransition`.
707+ *
708+ * Note: The View Transitions API is not available in all browsers. If the browser does not support
709+ * view transitions, the Router will not attempt to start a view transition and continue processing
710+ * the navigation as usual.
711+ *
712+ * @usageNotes
713+ *
714+ * Basic example of how you can enable the feature:
715+ * ```
716+ * const appRoutes: Routes = [];
717+ * bootstrapApplication(AppComponent,
718+ * {
719+ * providers: [
720+ * provideRouter(appRoutes, withViewTransitions())
721+ * ]
722+ * }
723+ * );
724+ * ```
725+ *
726+ * @returns A set of providers for use with `provideRouter`.
727+ * @see https://developer.chrome.com/docs/web-platform/view-transitions/
728+ * @see https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API
729+ * @experimental
730+ */
731+ export function withViewTransitions ( ) : ViewTransitionsFeature {
732+ const providers = [ { provide : CREATE_VIEW_TRANSITION , useValue : createViewTransition } ] ;
733+ return routerFeature ( RouterFeatureKind . ViewTransitionsFeature , providers ) ;
734+ }
735+
693736/**
694737 * A type alias that represents all Router features available for use with `provideRouter`.
695738 * Features can be enabled by adding special functions to the `provideRouter` call.
@@ -700,9 +743,9 @@ export function withComponentInputBinding(): ComponentInputBindingFeature {
700743 *
701744 * @publicApi
702745 */
703- export type RouterFeatures =
704- PreloadingFeature | DebugTracingFeature | InitialNavigationFeature | InMemoryScrollingFeature |
705- RouterConfigurationFeature | NavigationErrorHandlerFeature | ComponentInputBindingFeature ;
746+ export type RouterFeatures = PreloadingFeature | DebugTracingFeature | InitialNavigationFeature |
747+ InMemoryScrollingFeature | RouterConfigurationFeature | NavigationErrorHandlerFeature |
748+ ComponentInputBindingFeature | ViewTransitionsFeature ;
706749
707750/**
708751 * The list of features as an enum to uniquely type each feature.
@@ -717,4 +760,5 @@ export const enum RouterFeatureKind {
717760 RouterHashLocationFeature ,
718761 NavigationErrorHandlerFeature ,
719762 ComponentInputBindingFeature ,
763+ ViewTransitionsFeature ,
720764}
0 commit comments