docs: clarify location.subscribe behavior (#42272)

`Location.go` does not trigger the browser's `popstate` event because
the Angular Router uses `pushState` and `replaceState`. This can be
confusing when calling `Location.go` and using `Location.subscribe`.
This commit clarifies the behavior of `Location.subscribe` and points
developers to the `onUrlChanges` subscription instead.

Fixes #12691

PR Close #42272
This commit is contained in:
Andrew Scott 2021-05-24 08:20:46 -07:00 committed by Zach Arend
parent c3cbfc22e0
commit 3fe8762376
1 changed files with 6 additions and 1 deletions

View File

@ -30,7 +30,7 @@ export interface PopStateEvent {
*
* @usageNotes
*
* It's better to use the `Router#navigate` service to trigger route changes. Use
* It's better to use the `Router.navigate()` service to trigger route changes. Use
* `Location` only if you need to interact with or create normalized URLs outside of
* routing.
*
@ -228,9 +228,14 @@ export class Location {
/**
* Subscribes to the platform's `popState` events.
*
* Note: `Location.go()` does not trigger the `popState` event in the browser. Use
* `Location.onUrlChange()` to subscribe to URL changes instead.
*
* @param value Event that is triggered when the state history changes.
* @param exception The exception to throw.
*
* @see [onpopstate](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate)
*
* @returns Subscribed events.
*/
subscribe(