mirror of
https://github.com/angular/angular.git
synced 2026-11-24 15:37:51 -05:00
This reverts commit 5cc51880db.
PR Close #43845
This commit is contained in:
committed by
Andrew Kushnir
parent
de5a63ba40
commit
68cdcd3259
@@ -42,7 +42,7 @@
|
||||
"master": {
|
||||
"uncompressed": {
|
||||
"runtime": 2843,
|
||||
"main": 237487,
|
||||
"main": 238453,
|
||||
"polyfills": 37064,
|
||||
"src_app_lazy_lazy_module_ts": 795
|
||||
}
|
||||
@@ -68,4 +68,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1145,6 +1145,9 @@
|
||||
{
|
||||
"name": "defaultMalformedUriErrorHandler"
|
||||
},
|
||||
{
|
||||
"name": "defaultRouterHook"
|
||||
},
|
||||
{
|
||||
"name": "defaultScheduler"
|
||||
},
|
||||
|
||||
@@ -327,6 +327,30 @@ export interface NavigationTransition {
|
||||
guardsResult: boolean|UrlTree|null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type RouterHook = (snapshot: RouterStateSnapshot, runExtras: {
|
||||
appliedUrlTree: UrlTree,
|
||||
rawUrlTree: UrlTree,
|
||||
skipLocationChange: boolean,
|
||||
replaceUrl: boolean,
|
||||
navigationId: number
|
||||
}) => Observable<void>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function defaultRouterHook(snapshot: RouterStateSnapshot, runExtras: {
|
||||
appliedUrlTree: UrlTree,
|
||||
rawUrlTree: UrlTree,
|
||||
skipLocationChange: boolean,
|
||||
replaceUrl: boolean,
|
||||
navigationId: number
|
||||
}): Observable<void> {
|
||||
return of(null) as any;
|
||||
}
|
||||
|
||||
/**
|
||||
* The equivalent `IsActiveMatchOptions` options for `Router.isActive` is called with `true`
|
||||
* (exact = true).
|
||||
@@ -463,12 +487,16 @@ export class Router {
|
||||
private lastSuccessfulId: number = -1;
|
||||
|
||||
/**
|
||||
* Hook that enables you to pause navigation after the preactivation phase.
|
||||
* Hooks that enable you to pause navigation,
|
||||
* either before or after the preactivation phase.
|
||||
* Used by `RouterModule`.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
afterPreactivation: () => Observable<void> = () => of(void 0);
|
||||
hooks: {
|
||||
beforePreactivation: RouterHook,
|
||||
afterPreactivation: RouterHook
|
||||
} = {beforePreactivation: defaultRouterHook, afterPreactivation: defaultRouterHook};
|
||||
|
||||
/**
|
||||
* A strategy for extracting and merging URLs.
|
||||
@@ -731,6 +759,24 @@ export class Router {
|
||||
}
|
||||
}),
|
||||
|
||||
// Before Preactivation
|
||||
switchTap(t => {
|
||||
const {
|
||||
targetSnapshot,
|
||||
id: navigationId,
|
||||
extractedUrl: appliedUrlTree,
|
||||
rawUrl: rawUrlTree,
|
||||
extras: {skipLocationChange, replaceUrl}
|
||||
} = t;
|
||||
return this.hooks.beforePreactivation(targetSnapshot!, {
|
||||
navigationId,
|
||||
appliedUrlTree,
|
||||
rawUrlTree,
|
||||
skipLocationChange: !!skipLocationChange,
|
||||
replaceUrl: !!replaceUrl,
|
||||
});
|
||||
}),
|
||||
|
||||
// --- GUARDS ---
|
||||
tap(t => {
|
||||
const guardsStart = new GuardsCheckStart(
|
||||
@@ -808,7 +854,23 @@ export class Router {
|
||||
return undefined;
|
||||
}),
|
||||
|
||||
switchTap(() => this.afterPreactivation()),
|
||||
// --- AFTER PREACTIVATION ---
|
||||
switchTap((t: NavigationTransition) => {
|
||||
const {
|
||||
targetSnapshot,
|
||||
id: navigationId,
|
||||
extractedUrl: appliedUrlTree,
|
||||
rawUrl: rawUrlTree,
|
||||
extras: {skipLocationChange, replaceUrl}
|
||||
} = t;
|
||||
return this.hooks.afterPreactivation(targetSnapshot!, {
|
||||
navigationId,
|
||||
appliedUrlTree,
|
||||
rawUrlTree,
|
||||
skipLocationChange: !!skipLocationChange,
|
||||
replaceUrl: !!replaceUrl,
|
||||
});
|
||||
}),
|
||||
|
||||
map((t: NavigationTransition) => {
|
||||
const targetRouterState = createRouterState(
|
||||
|
||||
@@ -527,7 +527,7 @@ export class RouterInitializer implements OnDestroy {
|
||||
} else if (
|
||||
// TODO: enabled is deprecated as of v11, can be removed in v13
|
||||
opts.initialNavigation === 'enabled' || opts.initialNavigation === 'enabledBlocking') {
|
||||
router.afterPreactivation = () => {
|
||||
router.hooks.afterPreactivation = () => {
|
||||
// only the initial navigation should be delayed
|
||||
if (!this.initNavigation) {
|
||||
this.initNavigation = true;
|
||||
@@ -536,7 +536,7 @@ export class RouterInitializer implements OnDestroy {
|
||||
|
||||
// subsequent navigations should not be delayed
|
||||
} else {
|
||||
return of(void 0);
|
||||
return of(null) as any;
|
||||
}
|
||||
};
|
||||
router.initialNavigation();
|
||||
@@ -567,7 +567,7 @@ export class RouterInitializer implements OnDestroy {
|
||||
preloader.setUpPreloading();
|
||||
routerScroller.init();
|
||||
router.resetRootComponentType(ref.componentTypes[0]);
|
||||
this.resultOfPreactivationDone.next(void 0);
|
||||
this.resultOfPreactivationDone.next(null!);
|
||||
this.resultOfPreactivationDone.complete();
|
||||
}
|
||||
|
||||
|
||||
@@ -871,7 +871,7 @@ describe('Integration', () => {
|
||||
});
|
||||
|
||||
|
||||
it('should eagerly update the URL with urlUpdateStrategy="eager"',
|
||||
it('should eagerly update the URL with urlUpdateStrategy="eagar"',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = TestBed.createComponent(RootCmp);
|
||||
advance(fixture);
|
||||
@@ -885,21 +885,18 @@ describe('Integration', () => {
|
||||
expect(fixture.nativeElement).toHaveText('team 22 [ , right: ]');
|
||||
|
||||
router.urlUpdateStrategy = 'eager';
|
||||
router.events.subscribe(e => {
|
||||
if (!(e instanceof GuardsCheckStart)) {
|
||||
return;
|
||||
}
|
||||
(router as any).hooks.beforePreactivation = () => {
|
||||
expect(location.path()).toEqual('/team/33');
|
||||
expect(fixture.nativeElement).toHaveText('team 22 [ , right: ]');
|
||||
return of(null);
|
||||
});
|
||||
};
|
||||
router.navigateByUrl('/team/33');
|
||||
|
||||
advance(fixture);
|
||||
expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]');
|
||||
})));
|
||||
|
||||
it('should eagerly update the URL with urlUpdateStrategy="eager"',
|
||||
it('should eagerly update the URL with urlUpdateStrategy="eagar"',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = TestBed.createComponent(RootCmp);
|
||||
advance(fixture);
|
||||
@@ -929,7 +926,7 @@ describe('Integration', () => {
|
||||
expect(location.path()).toEqual('/login');
|
||||
})));
|
||||
|
||||
it('should set browserUrlTree with urlUpdateStrategy="eager" and false `shouldProcessUrl`',
|
||||
it('should set browserUrlTree with urlUpdateStrategy="eagar" and false `shouldProcessUrl`',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = TestBed.createComponent(RootCmp);
|
||||
advance(fixture);
|
||||
@@ -956,7 +953,7 @@ describe('Integration', () => {
|
||||
expect((router as any).browserUrlTree.toString()).toBe('/team/22');
|
||||
})));
|
||||
|
||||
it('should eagerly update URL after redirects are applied with urlUpdateStrategy="eager"',
|
||||
it('should eagerly update URL after redirects are applied with urlUpdateStrategy="eagar"',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = TestBed.createComponent(RootCmp);
|
||||
advance(fixture);
|
||||
@@ -990,7 +987,7 @@ describe('Integration', () => {
|
||||
expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]');
|
||||
})));
|
||||
|
||||
it('should set `state` with urlUpdateStrategy="eager"',
|
||||
it('should set `state` with urlUpdateStrategy="eagar"',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: SpyLocation) => {
|
||||
router.urlUpdateStrategy = 'eager';
|
||||
router.resetConfig([
|
||||
|
||||
Reference in New Issue
Block a user