Skip to content

Commit bdb6ae9

Browse files
JeanMechethePunderWoman
authored andcommitted
refactor(router): remove deprecated provideRoutes function.
`provideRoutes` was deprecated in v15. BREAKING CHANGE: `provideRoutes()` has been removed. Use `provideRouter()` or `ROUTES` as multi token if necessary.
1 parent c57ba8c commit bdb6ae9

File tree

10 files changed

+28
-162
lines changed

10 files changed

+28
-162
lines changed

adev/src/content/reference/migrations/route-lazy-loading.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ The schematic will attempt to find all the places where the application routes a
2525
- `RouterModule.forRoot` and `RouterModule.forChild`
2626
- `Router.resetConfig`
2727
- `provideRouter`
28-
- `provideRoutes`
2928
- variables of type `Routes` or `Route[]` (e.g. `const routes: Routes = [{...}]`)
3029

3130
The migration will check all the components in the routes, check if they are standalone and eagerly loaded, and if so, it will convert them to lazy loaded routes.

goldens/public-api/router/index.api.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,6 @@ export const PRIMARY_OUTLET = "primary";
589589
// @public
590590
export function provideRouter(routes: Routes, ...features: RouterFeatures[]): EnvironmentProviders;
591591

592-
// @public @deprecated
593-
export function provideRoutes(routes: Routes): Provider[];
594-
595592
// @public
596593
export type QueryParamsHandling = 'merge' | 'preserve' | 'replace' | '';
597594

packages/core/schematics/ng-generate/route-lazy-loading/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ The schematic will attempt to find all the places where the application routes a
2727
- `RouterModule.forRoot` and `RouterModule.forChild`
2828
- `Router.resetConfig`
2929
- `provideRouter`
30-
- `provideRoutes`
3130
- variables of type `Routes` or `Route[]` (e.g. `const routes: Routes = [{...}]`)
3231

3332
The migration will check all the components in the routes, check if they are standalone and eagerly loaded, and if so, it will convert them to lazy loaded routes.

packages/core/schematics/ng-generate/route-lazy-loading/to-lazy-routes.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import {findClassDeclaration} from '../../utils/typescript/class_declaration';
1515
import {findLiteralProperty} from '../../utils/typescript/property_name';
1616
import {
1717
isAngularRoutesArray,
18-
isProvideRoutesCallExpression,
18+
isProvideRouterCallExpression,
1919
isRouterCallExpression,
2020
isRouterModuleCallExpression,
21-
isRouterProviderCallExpression,
2221
isStandaloneComponent,
2322
} from './util';
2423

@@ -79,9 +78,8 @@ function findRoutesArrayToMigrate(sourceFile: ts.SourceFile, typeChecker: ts.Typ
7978
if (ts.isCallExpression(node)) {
8079
if (
8180
isRouterModuleCallExpression(node, typeChecker) ||
82-
isRouterProviderCallExpression(node, typeChecker) ||
8381
isRouterCallExpression(node, typeChecker) ||
84-
isProvideRoutesCallExpression(node, typeChecker)
82+
isProvideRouterCallExpression(node, typeChecker)
8583
) {
8684
const arg = node.arguments[0]; // ex: RouterModule.forRoot(routes) or provideRouter(routes)
8785
const routeFileImports = sourceFile.statements.filter(ts.isImportDeclaration);
@@ -95,7 +93,7 @@ function findRoutesArrayToMigrate(sourceFile: ts.SourceFile, typeChecker: ts.Typ
9593
});
9694
} else if (ts.isIdentifier(arg)) {
9795
// ex: reference to routes array: RouterModule.forRoot(routes)
98-
// RouterModule.forRoot(routes), provideRouter(routes), provideRoutes(routes)
96+
// RouterModule.forRoot(routes), provideRouter(routes)
9997
const symbol = typeChecker.getSymbolAtLocation(arg);
10098
if (!symbol?.declarations) return;
10199

packages/core/schematics/ng-generate/route-lazy-loading/util.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import ts from 'typescript';
109
import {findAngularDecorator, ReflectionHost} from '@angular/compiler-cli/private/migrations';
10+
import ts from 'typescript';
1111
import {findLiteralProperty} from '../../utils/typescript/property_name';
1212

1313
/**
@@ -103,26 +103,11 @@ export function isRouterCallExpression(node: ts.CallExpression, typeChecker: ts.
103103
return false;
104104
}
105105

106-
/**
107-
* Checks whether a node is a call expression to router provide function.
108-
* Example: provideRoutes(routes)
109-
*/
110-
export function isRouterProviderCallExpression(
111-
node: ts.CallExpression,
112-
typeChecker: ts.TypeChecker,
113-
) {
114-
if (ts.isIdentifier(node.expression)) {
115-
const moduleSymbol = typeChecker.getSymbolAtLocation(node.expression);
116-
return moduleSymbol && moduleSymbol.name === 'provideRoutes';
117-
}
118-
return false;
119-
}
120-
121106
/**
122107
* Checks whether a node is a call expression to provideRouter function.
123108
* Example: provideRouter(routes)
124109
*/
125-
export function isProvideRoutesCallExpression(
110+
export function isProvideRouterCallExpression(
126111
node: ts.CallExpression,
127112
typeChecker: ts.TypeChecker,
128113
) {

packages/core/schematics/test/standalone_routes_spec.ts

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {getSystemPath, normalize, virtualFs} from '@angular-devkit/core';
1010
import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
1111
import {HostTree} from '@angular-devkit/schematics';
1212
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
13-
import {resolve} from 'path';
1413
import {rmSync} from 'node:fs';
14+
import {resolve} from 'path';
1515

1616
describe('route lazy loading migration', () => {
1717
let runner: SchematicTestRunner;
@@ -285,55 +285,12 @@ describe('route lazy loading migration', () => {
285285
);
286286
});
287287

288-
it('should support provideRoutes', async () => {
289-
writeFile(
290-
'app.module.ts',
291-
`
292-
import {NgModule} from '@angular/core';
293-
import {provideRoutes} from '@angular/router';
294-
import {TestComponent} from './test';
295-
296-
const routes = [{path: 'test', component: TestComponent}];
297-
298-
@NgModule({
299-
providers: [provideRoutes(routes)],
300-
})
301-
export class AppModule {}
302-
`,
303-
);
304-
305-
writeFile(
306-
'test.ts',
307-
`
308-
import {Component} from '@angular/core';
309-
@Component({template: 'hello', standalone: true})
310-
export class TestComponent {}
311-
`,
312-
);
313-
314-
await runMigration('route-lazy-loading');
315-
316-
expect(stripWhitespace(tree.readContent('app.module.ts'))).toContain(
317-
stripWhitespace(`
318-
import {NgModule} from '@angular/core';
319-
import {provideRoutes} from '@angular/router';
320-
321-
const routes = [{path: 'test', loadComponent: () => import('./test').then(m => m.TestComponent)}];
322-
323-
@NgModule({
324-
providers: [provideRoutes(routes)],
325-
})
326-
export class AppModule {}
327-
`),
328-
);
329-
});
330-
331288
it('should skip not standalone components', async () => {
332289
writeFile(
333290
'app.module.ts',
334291
`
335292
import {NgModule} from '@angular/core';
336-
import {provideRoutes} from '@angular/router';
293+
import {provideRouter} from '@angular/router';
337294
import {TestComponent} from './test';
338295
import {StandaloneByDefaultComponent} from './standalone-by-default';
339296
import {NotStandaloneComponent} from './not-standalone';
@@ -345,7 +302,7 @@ describe('route lazy loading migration', () => {
345302
];
346303
347304
@NgModule({
348-
providers: [provideRoutes(routes)],
305+
providers: [provideRouter(routes)],
349306
})
350307
export class AppModule {}
351308
`,
@@ -386,7 +343,7 @@ describe('route lazy loading migration', () => {
386343
expect(stripWhitespace(tree.readContent('app.module.ts'))).toContain(
387344
stripWhitespace(`
388345
import {NgModule} from '@angular/core';
389-
import {provideRoutes} from '@angular/router';
346+
import {provideRouter} from '@angular/router';
390347
import {NotStandaloneComponent} from './not-standalone';
391348
392349
const routes = [
@@ -396,7 +353,7 @@ describe('route lazy loading migration', () => {
396353
];
397354
398355
@NgModule({
399-
providers: [provideRoutes(routes)],
356+
providers: [provideRouter(routes)],
400357
})
401358
export class AppModule {}
402359
`),

packages/router/src/index.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
export {createUrlTreeFromSnapshot} from './create_url_tree';
1010
export {RouterLink, RouterLinkWithHref} from './directives/router_link';
1111
export {RouterLinkActive} from './directives/router_link_active';
12-
export {RouterOutlet, ROUTER_OUTLET_DATA, RouterOutletContract} from './directives/router_outlet';
12+
export {ROUTER_OUTLET_DATA, RouterOutlet, RouterOutletContract} from './directives/router_outlet';
1313
export {
1414
ActivationEnd,
1515
ActivationStart,
@@ -35,36 +35,36 @@ export {
3535
Scroll,
3636
} from './events';
3737
export {
38+
CanActivate,
39+
CanActivateChild,
3840
CanActivateChildFn,
39-
MaybeAsync,
40-
GuardResult,
4141
CanActivateFn,
42+
CanDeactivate,
4243
CanDeactivateFn,
44+
CanLoad,
4345
CanLoadFn,
46+
CanMatch,
4447
CanMatchFn,
4548
Data,
4649
DefaultExport,
50+
GuardResult,
4751
LoadChildren,
4852
LoadChildrenCallback,
53+
MaybeAsync,
4954
NavigationBehaviorOptions,
5055
OnSameUrlNavigation,
56+
PartialMatchRouteSnapshot,
5157
QueryParamsHandling,
58+
RedirectCommand,
5259
RedirectFunction,
60+
Resolve,
5361
ResolveData,
5462
ResolveFn,
5563
Route,
5664
Routes,
5765
RunGuardsAndResolvers,
5866
UrlMatcher,
5967
UrlMatchResult,
60-
RedirectCommand,
61-
CanActivate,
62-
CanActivateChild,
63-
CanDeactivate,
64-
CanLoad,
65-
CanMatch,
66-
Resolve,
67-
PartialMatchRouteSnapshot,
6868
} from './models';
6969
export {ViewTransitionInfo, ViewTransitionsFeatureOptions} from './utils/view_transition';
7070

@@ -75,36 +75,35 @@ export {
7575
ComponentInputBindingFeature,
7676
DebugTracingFeature,
7777
DisabledInitialNavigationFeature,
78-
withViewTransitions,
79-
ViewTransitionsFeature,
8078
EnabledBlockingInitialNavigationFeature,
8179
InitialNavigationFeature,
8280
InMemoryScrollingFeature,
8381
NavigationErrorHandlerFeature,
8482
PreloadingFeature,
8583
provideRouter,
86-
withExperimentalPlatformNavigation,
87-
provideRoutes,
8884
RouterConfigurationFeature,
8985
RouterFeature,
9086
RouterFeatures,
9187
RouterHashLocationFeature,
88+
ViewTransitionsFeature,
9289
withComponentInputBinding,
9390
withDebugTracing,
9491
withDisabledInitialNavigation,
9592
withEnabledBlockingInitialNavigation,
93+
withExperimentalAutoCleanupInjectors,
94+
withExperimentalPlatformNavigation,
9695
withHashLocation,
9796
withInMemoryScrolling,
9897
withNavigationErrorHandler,
9998
withPreloading,
10099
withRouterConfig,
101-
withExperimentalAutoCleanupInjectors,
100+
withViewTransitions,
102101
} from './provide_router';
103102

104103
export {
105104
BaseRouteReuseStrategy,
106-
DetachedRouteHandle,
107105
destroyDetachedRouteHandle,
106+
DetachedRouteHandle,
108107
RouteReuseStrategy,
109108
} from './route_reuse_strategy';
110109
export {Router} from './router';
@@ -134,12 +133,12 @@ export {convertToParamMap, defaultUrlMatcher, ParamMap, Params, PRIMARY_OUTLET}
134133
export {UrlHandlingStrategy} from './url_handling_strategy';
135134
export {
136135
DefaultUrlSerializer,
136+
isActive,
137137
IsActiveMatchOptions,
138138
UrlSegment,
139139
UrlSegmentGroup,
140140
UrlSerializer,
141141
UrlTree,
142-
isActive,
143142
} from './url_tree';
144143
export {
145144
mapToCanActivate,

packages/router/src/provide_router.ts

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ export function provideRouter(routes: Routes, ...features: RouterFeatures[]): En
106106

107107
return makeEnvironmentProviders([
108108
{provide: ROUTES, multi: true, useValue: routes},
109-
typeof ngDevMode === 'undefined' || ngDevMode
110-
? {provide: ROUTER_IS_PROVIDED, useValue: true}
111-
: [],
112109
{provide: ActivatedRoute, useFactory: rootRoute},
113110
{provide: APP_BOOTSTRAP_LISTENER, multi: true, useFactory: getBootstrapListener},
114111
features.map((feature) => feature.ɵproviders),
@@ -139,56 +136,6 @@ function routerFeature<FeatureKind extends RouterFeatureKind>(
139136
return {ɵkind: kind, ɵproviders: providers};
140137
}
141138

142-
/**
143-
* An Injection token used to indicate whether `provideRouter` or `RouterModule.forRoot` was ever
144-
* called.
145-
*/
146-
export const ROUTER_IS_PROVIDED = new InjectionToken<boolean>(
147-
typeof ngDevMode !== 'undefined' && ngDevMode ? 'Router is provided' : '',
148-
{
149-
factory: () => false,
150-
},
151-
);
152-
153-
const routerIsProvidedDevModeCheck = {
154-
provide: ENVIRONMENT_INITIALIZER,
155-
multi: true,
156-
useFactory() {
157-
return () => {
158-
if (!inject(ROUTER_IS_PROVIDED)) {
159-
console.warn(
160-
'`provideRoutes` was called without `provideRouter` or `RouterModule.forRoot`. ' +
161-
'This is likely a mistake.',
162-
);
163-
}
164-
};
165-
},
166-
};
167-
168-
/**
169-
* Registers a DI provider for a set of routes.
170-
* @param routes The route configuration to provide.
171-
*
172-
* @usageNotes
173-
*
174-
* ```ts
175-
* @NgModule({
176-
* providers: [provideRoutes(ROUTES)]
177-
* })
178-
* class LazyLoadedChildModule {}
179-
* ```
180-
*
181-
* @deprecated If necessary, provide routes using the `ROUTES` `InjectionToken`.
182-
* @see {@link ROUTES}
183-
* @publicApi
184-
*/
185-
export function provideRoutes(routes: Routes): Provider[] {
186-
return [
187-
{provide: ROUTES, multi: true, useValue: routes},
188-
typeof ngDevMode === 'undefined' || ngDevMode ? routerIsProvidedDevModeCheck : [],
189-
];
190-
}
191-
192139
/**
193140
* A type alias for providers returned by `withInMemoryScrolling` for use with `provideRouter`.
194141
*

packages/router/src/router_module.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {NAVIGATION_ERROR_HANDLER} from './navigation_transition';
3434
import {
3535
getBootstrapListener,
3636
rootRoute,
37-
ROUTER_IS_PROVIDED,
3837
withComponentInputBinding,
3938
withDebugTracing,
4039
withDisabledInitialNavigation,
@@ -73,11 +72,6 @@ export const ROUTER_PROVIDERS: Provider[] = [
7372
ChildrenOutletContexts,
7473
{provide: ActivatedRoute, useFactory: rootRoute},
7574
RouterConfigLoader,
76-
// Only used to warn when `provideRoutes` is used without `RouterModule` or `provideRouter`. Can
77-
// be removed when `provideRoutes` is removed.
78-
typeof ngDevMode === 'undefined' || ngDevMode
79-
? {provide: ROUTER_IS_PROVIDED, useValue: true}
80-
: [],
8175
];
8276

8377
/**

0 commit comments

Comments
 (0)