angular-cn/packages/core/schematics/migrations/activated-route-snapshot-fr...
Kristiyan Kostadinov 190fa07b9a feat(router): add migration for ActivatedRouteSnapshot.fragment (#41092)
Adds a migration that casts the value of `ActivatedRouteSnapshot.fragment` to be non-nullable.

Also moves some code from the `AbstractControl.parent` migration so that it can be reused.

Relates to #37336.

PR Close #41092
2021-03-23 11:18:00 -07:00
..
BUILD.bazel feat(router): add migration for ActivatedRouteSnapshot.fragment (#41092) 2021-03-23 11:18:00 -07:00
README.md feat(router): add migration for ActivatedRouteSnapshot.fragment (#41092) 2021-03-23 11:18:00 -07:00
index.ts feat(router): add migration for ActivatedRouteSnapshot.fragment (#41092) 2021-03-23 11:18:00 -07:00
util.ts feat(router): add migration for ActivatedRouteSnapshot.fragment (#41092) 2021-03-23 11:18:00 -07:00

README.md

ActivatedRouteSnapshot.fragment migration

The value if ActivatedRouteSnapshot.fragment is becoming nullable. This migration adds non-null assertions to it.

Before

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

@Component({})
export class YourComponent {
  private _activatedRouteSnapshot: ActivatedRouteSnapshot;

  getFragmentValue() {
    return this._activatedRouteSnapshot.fragment.value;
  }
}

After

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

@Component({})
export class YourComponent {
  private _activatedRouteSnapshot: ActivatedRouteSnapshot;

  getFragmentValue() {
    return this._activatedRouteSnapshot.fragment!.value;
  }
}