UrlMatcherFactory | UI-Router
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class UrlMatcherFactory

Factory for UrlMatcher instances.

The factory is available to ng1 services as $urlMatcherFactor or ng1 providers as $urlMatcherFactoryProvider.

Hierarchy

  • UrlMatcherFactory

Index

Constructors

Methods

  • caseInsensitive(value: boolean): boolean
  • Defines whether URL matching should be case sensitive (the default behavior), or not.

  • Defines whether URL matching should be case sensitive (the default behavior), or not.

    Parameters

    • value: boolean
      :

      false to match URL in a case sensitive manner; otherwise true;

    Returns boolean

    :

    the current value of caseInsensitive


  • compile(pattern: string, config?: object): UrlMatcher
  • Creates a UrlMatcher for the specified pattern.

  • Creates a UrlMatcher for the specified pattern.

    Parameters

    • pattern: string
      :

      The URL pattern.

    • config Optional: object
      :

      The config object hash.

      • [key: string]: any

    Returns UrlMatcher

    :

    The UrlMatcher.


  • defaultSquashPolicy(value: string): boolean | string
  • Sets the default behavior when generating or matching URLs with default parameter values.

  • Sets the default behavior when generating or matching URLs with default parameter values.

    Parameters

    • value: string
      :

      A string that defines the default parameter URL squashing behavior.

      • nosquash: When generating an href with a default parameter value, do not squash the parameter value from the URL
      • slash: When generating an href with a default parameter value, squash (remove) the parameter value, and, if the
           parameter is surrounded by slashes, squash (remove) one slash from the URL
        
      • any other string, e.g. "~": When generating an href with a default parameter value, squash (remove)
           the parameter value from the URL and replace it with this string.
        

    Returns boolean | string

    :

    the current value of defaultSquashPolicy


  • isMatcher(object: any): boolean
  • Returns true if the specified object is a UrlMatcher, or false otherwise.

  • Returns true if the specified object is a UrlMatcher, or false otherwise.

    Parameters

    • object: any
      :

      The object to perform the type check against.

    Returns boolean

    :

    true if the object matches the UrlMatcher interface, by implementing all the same methods.


  • strictMode(value: boolean): boolean
  • Defines whether URLs should match trailing slashes, or not (the default behavior).

  • Defines whether URLs should match trailing slashes, or not (the default behavior).

    Parameters

    • value: boolean
      :

      false to match trailing slashes in URLs, otherwise true.

    Returns boolean

    :

    the current value of strictMode


  • type(name: string, definition?: Function | Type, definitionFn?: Function): any
  • Registers a custom Type object that can be used to generate URLs with typed parameters.

  • Registers a custom Type object that can be used to generate URLs with typed parameters.

    example
    
    var list = ['John', 'Paul', 'George', 'Ringo'];
    
    $urlMatcherFactoryProvider.type('listItem', {
      encode: function(item) {
        // Represent the list item in the URL using its corresponding index
        return list.indexOf(item);
      },
      decode: function(item) {
        // Look up the list item by index
        return list[parseInt(item, 10)];
      },
      is: function(item) {
        // Ensure the item is valid by checking to see that it appears
        // in the list
        return list.indexOf(item) > -1;
      }
    });
    
    $stateProvider.state('list', {
      url: "/list/{item:listItem}",
      controller: function($scope, $stateParams) {
        console.log($stateParams.item);
      }
    });
    
    // ...
    
    // Changes URL to '/list/3', logs "Ringo" to the console
    $state.go('list', { item: "Ringo" });
    

    Parameters

    • name: string
      :

      The type name.

    • definition Optional: Function | Type
      :

      The type definition. See Type for information on the values accepted.

    • definitionFn Optional: Function
      :

      A function that is injected before the app runtime starts. The result of this function is merged into the existing definition. See Type for information on the values accepted.

    Returns any

    :
    • if a type was registered: the UrlMatcherFactory
      • if only the name parameter was specified: the currently registered Type object, or undefined

    This is a simple example of a custom type that encodes and decodes items from an array, using the array index as the URL-encoded value:


Generated using TypeDoc