@@ -22,6 +22,7 @@ import {ROUTER_SCROLLER, RouterScroller} from './router_scroller';
22
22
import { ActivatedRoute } from './router_state' ;
23
23
import { UrlSerializer } from './url_tree' ;
24
24
import { afterNextNavigation } from './utils/navigations' ;
25
+ import { CREATE_VIEW_TRANSITION , createViewTransition } from './utils/view_transition' ;
25
26
26
27
27
28
/**
@@ -661,6 +662,16 @@ export function withNavigationErrorHandler(fn: (error: NavigationError) => void)
661
662
export type ComponentInputBindingFeature =
662
663
RouterFeature < RouterFeatureKind . ComponentInputBindingFeature > ;
663
664
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
+
664
675
/**
665
676
* Enables binding information from the `Router` state directly to the inputs of the component in
666
677
* `Route` configurations.
@@ -690,6 +701,38 @@ export function withComponentInputBinding(): ComponentInputBindingFeature {
690
701
return routerFeature ( RouterFeatureKind . ComponentInputBindingFeature , providers ) ;
691
702
}
692
703
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
+
693
736
/**
694
737
* A type alias that represents all Router features available for use with `provideRouter`.
695
738
* Features can be enabled by adding special functions to the `provideRouter` call.
@@ -700,9 +743,9 @@ export function withComponentInputBinding(): ComponentInputBindingFeature {
700
743
*
701
744
* @publicApi
702
745
*/
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 ;
706
749
707
750
/**
708
751
* The list of features as an enum to uniquely type each feature.
@@ -717,4 +760,5 @@ export const enum RouterFeatureKind {
717
760
RouterHashLocationFeature ,
718
761
NavigationErrorHandlerFeature ,
719
762
ComponentInputBindingFeature ,
763
+ ViewTransitionsFeature ,
720
764
}
0 commit comments