refactor(docs-infra): Move router-specific app configuration to separate file (#60722)

This moves the router configuration for the app to a separate file since
there is a lot of it.

PR Close #60722
This commit is contained in:
Andrew Scott
2025-04-02 21:35:44 -07:00
parent 92c4123a74
commit 558d76ec5d
2 changed files with 56 additions and 42 deletions
+2 -42
View File
@@ -26,56 +26,21 @@ import {
windowProvider,
} from '@angular/docs';
import {provideClientHydration} from '@angular/platform-browser';
import {
RouteReuseStrategy,
Router,
TitleStrategy,
createUrlTreeFromSnapshot,
provideRouter,
withComponentInputBinding,
withInMemoryScrolling,
withViewTransitions,
} from '@angular/router';
import environment from './environment';
import {PREVIEWS_COMPONENTS_MAP} from './../assets/previews/previews';
import {ADevTitleStrategy} from './core/services/a-dev-title-strategy';
import {AnalyticsService} from './core/services/analytics/analytics.service';
import {ContentLoader} from './core/services/content-loader.service';
import {CustomErrorHandler} from './core/services/errors-handling/error-handler';
import {ExampleContentLoader} from './core/services/example-content-loader.service';
import {ReuseTutorialsRouteStrategy} from './features/tutorial/tutorials-route-reuse-strategy';
import {routes} from './routes';
import {CURRENT_MAJOR_VERSION} from './core/providers/current-version';
import {AppScroller} from './app-scroller';
import {routerProviders} from './router_providers';
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(
routes,
withInMemoryScrolling(),
withViewTransitions({
onViewTransitionCreated: ({transition, to}) => {
const router = inject(Router);
const toTree = createUrlTreeFromSnapshot(to, []);
// Skip the transition if the only thing changing is the fragment and queryParams
if (
router.isActive(toTree, {
paths: 'exact',
matrixParams: 'exact',
fragment: 'ignored',
queryParams: 'ignored',
})
) {
transition.skipTransition();
}
},
}),
withComponentInputBinding(),
),
routerProviders,
provideExperimentalZonelessChangeDetection(),
provideClientHydration(),
provideHttpClient(withFetch()),
provideEnvironmentInitializer(() => inject(AppScroller)),
provideEnvironmentInitializer(() => inject(AnalyticsService)),
provideAlgoliaSearchClient(environment),
{
@@ -87,15 +52,10 @@ export const appConfig: ApplicationConfig = {
{provide: PREVIEWS_COMPONENTS, useValue: PREVIEWS_COMPONENTS_MAP},
{provide: DOCS_CONTENT_LOADER, useClass: ContentLoader},
{provide: EXAMPLE_VIEWER_CONTENT_LOADER, useClass: ExampleContentLoader},
{
provide: RouteReuseStrategy,
useClass: ReuseTutorialsRouteStrategy,
},
{
provide: WINDOW,
useFactory: (document: Document) => windowProvider(document),
deps: [DOCUMENT],
},
{provide: TitleStrategy, useClass: ADevTitleStrategy},
],
};
+54
View File
@@ -0,0 +1,54 @@
/*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {inject, provideEnvironmentInitializer} from '@angular/core';
import {
provideRouter,
withInMemoryScrolling,
Router,
withViewTransitions,
createUrlTreeFromSnapshot,
withComponentInputBinding,
RouteReuseStrategy,
TitleStrategy,
} from '@angular/router';
import {routes} from './routes';
import {ADevTitleStrategy} from './core/services/a-dev-title-strategy';
import {ReuseTutorialsRouteStrategy} from './features/tutorial/tutorials-route-reuse-strategy';
import {AppScroller} from './app-scroller';
export const routerProviders = [
provideRouter(
routes,
withInMemoryScrolling(),
withViewTransitions({
onViewTransitionCreated: ({transition, to}) => {
const router = inject(Router);
const toTree = createUrlTreeFromSnapshot(to, []);
// Skip the transition if the only thing changing is the fragment and queryParams
if (
router.isActive(toTree, {
paths: 'exact',
matrixParams: 'exact',
fragment: 'ignored',
queryParams: 'ignored',
})
) {
transition.skipTransition();
}
},
}),
withComponentInputBinding(),
),
{
provide: RouteReuseStrategy,
useClass: ReuseTutorialsRouteStrategy,
},
{provide: TitleStrategy, useClass: ADevTitleStrategy},
provideEnvironmentInitializer(() => inject(AppScroller)),
];