feat(router): add pathParamsOrQueryParamsChange mode for runGuardsAndResolvers (#27464)
This option means guards and resolvers will ignore changes to matrix parameters. Guards and resolvers will be rerun when the path changes, when path parameters change, or when query parameters change. The primary use case for such a mode is when updating the UI and getting the URL to be in sync with local changes. For example, if displaying a sortable table, changing the sort direction is often handled by the table itself. But you would want to update the URL to be in sync with what's being displayed to the user. As long as the table sort direction is stored as a matrix parameter, you can use this option to update the URL without causing the overhead of re-running guards and resolvers. Related to #26861 #18253 PR Close #27464
This commit is contained in:
@ -42,9 +42,11 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
|
||||
* mode ignores query param changes.
|
||||
* - `paramsOrQueryParamsChange` - Guards and resolvers will run when any parameters change. This
|
||||
* includes path, matrix, and query params.
|
||||
* - `pathParamsChange` Run guards and resolvers path or any path params change. This mode is
|
||||
* - `pathParamsChange` - Run guards and resolvers path or any path params change. This mode is
|
||||
* useful if you want to ignore changes to all optional parameters such as query *and* matrix
|
||||
* params.
|
||||
* - `pathParamsOrQueryParamsChange` - Same as `pathParamsChange`, but also rerun when any query
|
||||
* param changes
|
||||
* - `always` - Run guards and resolvers on every navigation.
|
||||
* - `children` is an array of child route definitions.
|
||||
* - `loadChildren` is a reference to lazy loaded child routes. See `LoadChildren` for more
|
||||
@ -366,8 +368,8 @@ export type QueryParamsHandling = 'merge' | 'preserve' | '';
|
||||
* See `Routes` for more details.
|
||||
* @publicApi
|
||||
*/
|
||||
export type RunGuardsAndResolvers =
|
||||
'pathParamsChange' | 'paramsChange' | 'paramsOrQueryParamsChange' | 'always';
|
||||
export type RunGuardsAndResolvers = 'pathParamsChange' | 'pathParamsOrQueryParamsChange' |
|
||||
'paramsChange' | 'paramsOrQueryParamsChange' | 'always';
|
||||
|
||||
/**
|
||||
* See `Routes` for more details.
|
||||
|
@ -151,6 +151,10 @@ function shouldRunGuardsAndResolvers(
|
||||
case 'pathParamsChange':
|
||||
return !equalPath(curr.url, future.url);
|
||||
|
||||
case 'pathParamsOrQueryParamsChange':
|
||||
return !equalPath(curr.url, future.url) ||
|
||||
!shallowEqual(curr.queryParams, future.queryParams);
|
||||
|
||||
case 'always':
|
||||
return true;
|
||||
|
||||
|
Reference in New Issue
Block a user