Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
docs(router): Deprecate writing to router.navigated property
The router.navigated property is meant to be read-only externally. Writing to it
is simply a workaround for APIs that had previously been missing in the Router

DEPRECATED:
The router.navigated property is meant to be read-only externally. Writing to it
is simply a workaround for APIs that had previously been missing in the Router.
To force reloads, pass `onSameUrlNavigation: 'reload'` in the options of
`Router.navigate`.
  • Loading branch information
atscott committed Nov 22, 2022
commit 1c198d4a30b68e5b7e9e51b2a1234c2f5f5c97c0
6 changes: 4 additions & 2 deletions aio/content/guide/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ The injector no longer requires the Reflect polyfill, reducing application size
<a id="router-writable-properties"></a>

None of the public properties of the `Router` are meant to be writeable.
They should all be configured using other methods, all of which have been
documented.
They should all be configured using other methods.

The following strategies are meant to be configured by registering the
application strategy in DI via the `providers` in the root `NgModule` or
Expand All @@ -403,6 +402,9 @@ available in `provideRouter`:
* `errorHandler` - Developers should instead subscribe to `Router.events`
and filter for `NavigationError`.

The following properties are meant to be read-only:
* navigated - This has been found to be used as a way to force the router to reprocess a URL when `onSameUrlNavigation` is set to `'ignore'`. Instead, set `onSameUrlNavigation: 'reload'` in the extra options of the `Router.navigate` method.

<a id="relativeLinkResolution"></a>

The `relativeLinkResolution` option is deprecated and being removed.
Expand Down
3 changes: 2 additions & 1 deletion goldens/public-api/router/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ export class Router {
malformedUriErrorHandler: (error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree;
navigate(commands: any[], extras?: NavigationExtras): Promise<boolean>;
navigateByUrl(url: string | UrlTree, extras?: NavigationBehaviorOptions): Promise<boolean>;
navigated: boolean;
get navigated(): boolean;
set navigated(value: boolean);
// (undocumented)
ngOnDestroy(): void;
// @deprecated
Expand Down
18 changes: 15 additions & 3 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,23 @@ export class Router {
(error: URIError, urlSerializer: UrlSerializer,
url: string) => UrlTree = defaultMalformedUriErrorHandler;

private _navigated = false;
/**
* True if at least one navigation event has occurred,
* false otherwise.
* True if at least one navigation has occurred, false otherwise.
*/
navigated: boolean = false;
get navigated() {
return this._navigated;
}
/**
* @deprecated The navigated property is not meant to be writable. If you want to force the
* router to reprocess a URL during navigation, set `onSameUrlNavigation: 'reload'` in the
* extra options of `Router.navigate`.
*
* @see NavigationBehaviorOptions
*/
set navigated(value: boolean) {
this._navigated = value;
}
private lastSuccessfulId: number = -1;

/**
Expand Down