Skip to content

Commit d76761b

Browse files
ocombemhevery
authored andcommitted
refactor(router): remove deprecated initialNavigation options (angular#18781)
BREAKING CHANGE: the values `true`, `false`, `legacy_enabled` and `legacy_disabled` for the router parameter `initialNavigation` have been removed as they were deprecated. Use `enabled` or `disabled` instead. PR Close angular#18781
1 parent c055dc7 commit d76761b

File tree

3 files changed

+6
-106
lines changed

3 files changed

+6
-106
lines changed

aio/content/examples/ngmodule/src/index.3.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<base href="/">
4+
<base href="/index.3.html">
55
<title>NgModule - Contact</title>
66
<meta charset="UTF-8">
77
<meta name="viewport" content="width=device-width, initial-scale=1">

packages/router/src/router_module.ts

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -218,24 +218,14 @@ export function provideRoutes(routes: Routes): any {
218218
* The bootstrap is blocked until the initial navigation is complete.
219219
* * 'disabled' - the initial navigation is not performed. The location listener is set up before
220220
* the root component gets created.
221-
* * 'legacy_enabled'- the initial navigation starts after the root component has been created.
222-
* The bootstrap is not blocked until the initial navigation is complete. @deprecated
223-
* * 'legacy_disabled'- the initial navigation is not performed. The location listener is set up
224-
* after @deprecated
225-
* the root component gets created.
226-
* * `true` - same as 'legacy_enabled'. @deprecated since v4
227-
* * `false` - same as 'legacy_disabled'. @deprecated since v4
228221
*
229222
* The 'enabled' option should be used for applications unless there is a reason to have
230223
* more control over when the router starts its initial navigation due to some complex
231224
* initialization logic. In this case, 'disabled' should be used.
232225
*
233-
* The 'legacy_enabled' and 'legacy_disabled' should not be used for new applications.
234-
*
235226
* @experimental
236227
*/
237-
export type InitialNavigation =
238-
true | false | 'enabled' | 'disabled' | 'legacy_enabled' | 'legacy_disabled';
228+
export type InitialNavigation = 'enabled' | 'disabled';
239229

240230
/**
241231
* @whatItDoes Represents options to configure the router.
@@ -254,7 +244,7 @@ export interface ExtraOptions {
254244
useHash?: boolean;
255245

256246
/**
257-
* Disables the initial navigation.
247+
* Enables/Disables the initial navigation (enabled by default).
258248
*/
259249
initialNavigation?: InitialNavigation;
260250

@@ -332,14 +322,12 @@ export class RouterInitializer {
332322
const router = this.injector.get(Router);
333323
const opts = this.injector.get(ROUTER_CONFIGURATION);
334324

335-
if (this.isLegacyDisabled(opts) || this.isLegacyEnabled(opts)) {
336-
resolve(true);
337-
338-
} else if (opts.initialNavigation === 'disabled') {
325+
if (opts.initialNavigation === 'disabled') {
339326
router.setUpLocationChangeListener();
340327
resolve(true);
341328

342-
} else if (opts.initialNavigation === 'enabled') {
329+
} else if (
330+
opts.initialNavigation === 'enabled' || typeof opts.initialNavigation === 'undefined') {
343331
router.hooks.afterPreactivation = () => {
344332
// only the initial navigation should be delayed
345333
if (!this.initNavigation) {
@@ -372,26 +360,11 @@ export class RouterInitializer {
372360
return;
373361
}
374362

375-
if (this.isLegacyEnabled(opts)) {
376-
router.initialNavigation();
377-
} else if (this.isLegacyDisabled(opts)) {
378-
router.setUpLocationChangeListener();
379-
}
380-
381363
preloader.setUpPreloading();
382364
router.resetRootComponentType(ref.componentTypes[0]);
383365
this.resultOfPreactivationDone.next(null !);
384366
this.resultOfPreactivationDone.complete();
385367
}
386-
387-
private isLegacyEnabled(opts: ExtraOptions): boolean {
388-
return opts.initialNavigation === 'legacy_enabled' || opts.initialNavigation === true ||
389-
opts.initialNavigation === undefined;
390-
}
391-
392-
private isLegacyDisabled(opts: ExtraOptions): boolean {
393-
return opts.initialNavigation === 'legacy_disabled' || opts.initialNavigation === false;
394-
}
395368
}
396369

397370
export function getAppInitializer(r: RouterInitializer) {

packages/router/test/bootstrap.spec.ts

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -90,48 +90,6 @@ describe('bootstrap', () => {
9090
});
9191
});
9292

93-
it('should NOT wait for resolvers to complete when initialNavigation = legacy_enabled',
94-
(done) => {
95-
@Component({selector: 'test', template: 'test'})
96-
class TestCmpLegacyEnabled {
97-
}
98-
99-
@NgModule({
100-
imports: [
101-
BrowserModule,
102-
RouterModule.forRoot(
103-
[{path: '**', component: TestCmpLegacyEnabled, resolve: {test: TestResolver}}],
104-
{useHash: true, initialNavigation: 'legacy_enabled'})
105-
],
106-
declarations: [RootCmp, TestCmpLegacyEnabled],
107-
bootstrap: [RootCmp],
108-
providers: [...testProviders, TestResolver],
109-
schemas: [CUSTOM_ELEMENTS_SCHEMA]
110-
})
111-
class TestModule {
112-
constructor(router: Router) {
113-
log.push('TestModule');
114-
router.events.subscribe(e => log.push(e.constructor.name));
115-
}
116-
}
117-
118-
platformBrowserDynamic([]).bootstrapModule(TestModule).then(res => {
119-
const router = res.injector.get(Router);
120-
expect(router.routerState.snapshot.root.firstChild).toBeNull();
121-
// ResolveEnd has not been emitted yet because bootstrap returned too early
122-
expect(log).toEqual([
123-
'TestModule', 'RootCmp', 'NavigationStart', 'RoutesRecognized', 'GuardsCheckStart',
124-
'GuardsCheckEnd', 'ResolveStart'
125-
]);
126-
127-
router.events.subscribe((e) => {
128-
if (e instanceof NavigationEnd) {
129-
done();
130-
}
131-
});
132-
});
133-
});
134-
13593
it('should not run navigation when initialNavigation = disabled', (done) => {
13694
@Component({selector: 'test', template: 'test'})
13795
class TestCmpDiabled {
@@ -162,37 +120,6 @@ describe('bootstrap', () => {
162120
});
163121
});
164122

165-
it('should not run navigation when initialNavigation = legacy_disabled', (done) => {
166-
@Component({selector: 'test', template: 'test'})
167-
class TestCmpLegacyDisabled {
168-
}
169-
170-
@NgModule({
171-
imports: [
172-
BrowserModule,
173-
RouterModule.forRoot(
174-
[{path: '**', component: TestCmpLegacyDisabled, resolve: {test: TestResolver}}],
175-
{useHash: true, initialNavigation: 'legacy_disabled'})
176-
],
177-
declarations: [RootCmp, TestCmpLegacyDisabled],
178-
bootstrap: [RootCmp],
179-
providers: [...testProviders, TestResolver],
180-
schemas: [CUSTOM_ELEMENTS_SCHEMA]
181-
})
182-
class TestModule {
183-
constructor(router: Router) {
184-
log.push('TestModule');
185-
router.events.subscribe(e => log.push(e.constructor.name));
186-
}
187-
}
188-
189-
platformBrowserDynamic([]).bootstrapModule(TestModule).then(res => {
190-
const router = res.injector.get(Router);
191-
expect(log).toEqual(['TestModule', 'RootCmp']);
192-
done();
193-
});
194-
});
195-
196123
it('should not init router navigation listeners if a non root component is bootstrapped',
197124
(done) => {
198125
@NgModule({

0 commit comments

Comments
 (0)