angular-cn/packages/core/schematics/migrations/navigation-extras-omissions
Kristiyan Kostadinov 7849fdde09 feat(router): add migration to update calls to navigateByUrl and createUrlTree with invalid parameters (#38825)
In #38227 the signatures of `navigateByUrl` and `createUrlTree` were updated to exclude unsupported
properties from their `extras` parameter. This migration looks for the relevant method calls that
pass in an `extras` parameter and drops the unsupported properties.

**Before:**
```
this._router.navigateByUrl('/', {skipLocationChange: false, fragment: 'foo'});
```

**After:**
```
this._router.navigateByUrl('/', {
  /* Removed unsupported properties by Angular migration: fragment. */
  skipLocationChange: false
});
```

These changes also move the method call detection logic out of the `Renderer2` migration and into
a common place so that it can be reused in other migrations.

PR Close #38825
2020-09-16 15:16:18 -07:00
..
BUILD.bazel feat(router): add migration to update calls to navigateByUrl and createUrlTree with invalid parameters (#38825) 2020-09-16 15:16:18 -07:00
README.md feat(router): add migration to update calls to navigateByUrl and createUrlTree with invalid parameters (#38825) 2020-09-16 15:16:18 -07:00
index.ts feat(router): add migration to update calls to navigateByUrl and createUrlTree with invalid parameters (#38825) 2020-09-16 15:16:18 -07:00
util.ts feat(router): add migration to update calls to navigateByUrl and createUrlTree with invalid parameters (#38825) 2020-09-16 15:16:18 -07:00

README.md

Router.navigateByUrl and Router.createUrlTree extras migration

Previously the extras parameter of Router.navigateByUrl and Router.createUrlTree accepted the full NavigationExtras object, even though only a subset of properties was supported. This migration removes the unsupported properties from the relevant method call sites.

Before

import { Component } from '@angular/core';
import { Router } from '@angular/router';

@Component({})
export class MyComponent {
  constructor(private _router: Router) {}

  goHome() {
    this._router.navigateByUrl('/', {skipLocationChange: false, fragment: 'foo'});
  }
}

After

import { Component } from '@angular/core';
import { Router } from '@angular/router';

@Component({})
export class MyComponent {
  constructor(private _router: Router) {}

  goHome() {
    this._router.navigateByUrl('/', { /* Removed unsupported properties by Angular migration: fragment. */ skipLocationChange: false });
  }
}