https://github.com/angular/angular
Raw File
Tip revision: 154129b9defa9295f4684c595d1981c9b3c970c5 authored by Alex Rickabaugh on 01 April 2021, 21:35:30 UTC
release: cut the v11.2.8 release (#41419)
Tip revision: 154129b
url_handling_strategy.ts
/**
 * @license
 * Copyright Google LLC All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://angular.io/license
 */

import {UrlTree} from './url_tree';

/**
 * @description
 *
 * Provides a way to migrate AngularJS applications to Angular.
 *
 * @publicApi
 */
export abstract class UrlHandlingStrategy {
  /**
   * Tells the router if this URL should be processed.
   *
   * When it returns true, the router will execute the regular navigation.
   * When it returns false, the router will set the router state to an empty state.
   * As a result, all the active components will be destroyed.
   *
   */
  abstract shouldProcessUrl(url: UrlTree): boolean;

  /**
   * Extracts the part of the URL that should be handled by the router.
   * The rest of the URL will remain untouched.
   */
  abstract extract(url: UrlTree): UrlTree;

  /**
   * Merges the URL fragment with the rest of the URL.
   */
  abstract merge(newUrlPart: UrlTree, rawUrl: UrlTree): UrlTree;
}

/**
 * @publicApi
 */
export class DefaultUrlHandlingStrategy implements UrlHandlingStrategy {
  shouldProcessUrl(url: UrlTree): boolean {
    return true;
  }
  extract(url: UrlTree): UrlTree {
    return url;
  }
  merge(newUrlPart: UrlTree, wholeUrl: UrlTree): UrlTree {
    return newUrlPart;
  }
}
back to top