Skip to content

Commit

Permalink
fix(router): Update Navigation#initialUrl to match documentation an…
Browse files Browse the repository at this point in the history
…d reality (angular#43863)

BREAKING CHANGE:

* The type of `initialUrl` is set to `string|UrlTree` but in reality,
  the `Router` only sets it to a value that will always be `UrlTree`
* `initialUrl` is documented as "The target URL passed into the
  `Router#navigateByUrl()` call before navigation" but the value
  actually gets set to something completely different. It's set to the
  current internal `UrlTree` of the Router at the time navigation
  occurs.

With this change, there is no exact replacement for the old value of
`initialUrl` because it was enver intended to be exposed.
`Router.url` is likely the best replacement for this.
In more specific use-cases, tracking the `finalUrl` between successful
navigations can also be used as a replacement.

PR Close angular#43863
  • Loading branch information
atscott authored and josmar-crwdstffng committed Apr 8, 2022
1 parent ff62365 commit 02409f3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion goldens/public-api/router/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export interface Navigation {
extras: NavigationExtras;
finalUrl?: UrlTree;
id: number;
initialUrl: string | UrlTree;
initialUrl: UrlTree;
previousNavigation: Navigation | null;
trigger: 'imperative' | 'popstate' | 'hashchange';
}
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export interface Navigation {
* The target URL passed into the `Router#navigateByUrl()` call before navigation. This is
* the value before the router has parsed or applied redirects to it.
*/
initialUrl: string|UrlTree;
initialUrl: UrlTree;
/**
* The initial target URL after being parsed with `UrlSerializer.extract()`.
*/
Expand Down Expand Up @@ -650,7 +650,7 @@ export class Router {
tap(t => {
this.currentNavigation = {
id: t.id,
initialUrl: t.currentRawUrl,
initialUrl: t.rawUrl,
extractedUrl: t.extractedUrl,
trigger: t.source,
extras: t.extras,
Expand Down

0 comments on commit 02409f3

Please sign in to comment.