Skip to content

Commit

Permalink
refactor(router): Make nextState parameter on canDeactivate required
Browse files Browse the repository at this point in the history
nextState is always provided, thus making it required.
  • Loading branch information
JeanMeche committed Nov 12, 2022
1 parent 954f700 commit 92f7799
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion goldens/public-api/router/index.md
Expand Up @@ -133,7 +133,7 @@ export type CanActivateFn = (route: ActivatedRouteSnapshot, state: RouterStateSn
// @public
export interface CanDeactivate<T> {
// (undocumented)
canDeactivate(component: T, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree;
canDeactivate(component: T, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree;
}

// @public
Expand Down
16 changes: 7 additions & 9 deletions packages/router/src/models.ts
Expand Up @@ -6,14 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/

import {EnvironmentInjector, EnvironmentProviders, InjectionToken, NgModuleFactory, Provider, ProviderToken, Type} from '@angular/core';
import {EnvironmentInjector, EnvironmentProviders, InjectionToken, NgModuleFactory, Provider, Type,} from '@angular/core';
import {Observable} from 'rxjs';

import {DeprecatedLoadChildren} from './deprecated_load_children';
import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state';
import {UrlSegment, UrlSegmentGroup, UrlTree} from './url_tree';


/**
* Represents a route configuration for the Router service.
* An array of `Route` objects, used in `Router.config` and for nested route configurations
Expand Down Expand Up @@ -74,7 +73,7 @@ export type UrlMatcher = (segments: UrlSegment[], group: UrlSegmentGroup, route:
* @publicApi
*/
export type Data = {
[key: string|symbol]: any
[key: string|symbol]: any;
};

/**
Expand All @@ -86,7 +85,7 @@ export type Data = {
* @publicApi
*/
export type ResolveData = {
[key: string|symbol]: any|ResolveFn<unknown>
[key: string|symbol]: any|ResolveFn<unknown>;
};

/**
Expand Down Expand Up @@ -139,7 +138,7 @@ export interface DefaultExport<T> {
* @see [Route.loadChildren](api/router/Route#loadChildren)
* @publicApi
*/
export type LoadChildrenCallback = () => Type<any>|NgModuleFactory<any>|Routes|
export type LoadChildrenCallback = () => |Type<any>|NgModuleFactory<any>|Routes|
Observable<Type<any>|Routes|DefaultExport<Type<any>>|DefaultExport<Routes>>|
Promise<NgModuleFactory<any>|Type<any>|Routes|DefaultExport<Type<any>>|DefaultExport<Routes>>;

Expand Down Expand Up @@ -185,7 +184,7 @@ export type QueryParamsHandling = 'merge'|'preserve'|'';
* @publicApi
*/
export type RunGuardsAndResolvers =
'pathParamsChange'|'pathParamsOrQueryParamsChange'|'paramsChange'|'paramsOrQueryParamsChange'|
|'pathParamsChange'|'pathParamsOrQueryParamsChange'|'paramsChange'|'paramsOrQueryParamsChange'|
'always'|((from: ActivatedRouteSnapshot, to: ActivatedRouteSnapshot) => boolean);

/**
Expand Down Expand Up @@ -463,7 +462,7 @@ export interface Route {
/**
* An object specifying a lazy-loaded component.
*/
loadComponent?: () => Type<unknown>| Observable<Type<unknown>|DefaultExport<Type<unknown>>>|
loadComponent?: () => | Type<unknown>| Observable<Type<unknown>|DefaultExport<Type<unknown>>>|
Promise<Type<unknown>|DefaultExport<Type<unknown>>>;
/**
* Filled for routes `loadComponent` once the component is loaded.
Expand Down Expand Up @@ -851,7 +850,7 @@ export type CanActivateChildFn = (childRoute: ActivatedRouteSnapshot, state: Rou
export interface CanDeactivate<T> {
canDeactivate(
component: T, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot,
nextState?: RouterStateSnapshot): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean
nextState: RouterStateSnapshot): Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean
|UrlTree;
}

Expand Down Expand Up @@ -1179,7 +1178,6 @@ export interface CanLoad {
export type CanLoadFn = (route: Route, segments: UrlSegment[]) =>
Observable<boolean|UrlTree>|Promise<boolean|UrlTree>|boolean|UrlTree;


/**
* @description
*
Expand Down

0 comments on commit 92f7799

Please sign in to comment.