Skip to main content
The UrlConfig API customizes the URL behavior and retrieves URL configuration metadata.

Overview

Access the UrlConfig API via router.urlService.config.
class UrlConfig implements Disposable

Configuration Methods

caseInsensitive()

Defines whether URL matching should be case sensitive.
public caseInsensitive(value?: boolean): boolean
Parameters:
  • value - false to match URLs in a case-sensitive manner; true for case-insensitive (optional)
Returns: The current value of caseInsensitive. Example:
// Allow case insensitive url matches
urlService.config.caseInsensitive(true);

strictMode()

Defines whether URLs should match trailing slashes.
public strictMode(value?: boolean): boolean
Parameters:
  • value - false to match trailing slashes in URLs; true for strict mode (optional)
Returns: The current value of strictMode. Default: true (trailing slashes must match exactly) Example:
// Allow optional trailing slashes
urlService.config.strictMode(false);

defaultSquashPolicy()

Sets the default behavior when generating or matching URLs with default parameter values.
public defaultSquashPolicy(value?: boolean | string): boolean | string
Parameters:
  • value - The squash policy:
    • false or 'nosquash': Don’t squash default parameter values from the URL
    • true or 'slash': Squash default values and remove one slash if surrounded by slashes
    • Any other string (e.g., '~'): Replace the default value with this string
Returns: The current value of defaultSquashPolicy. Example:
// Remove default parameter values from the url
urlService.config.defaultSquashPolicy(true);

type()

Creates and registers a custom parameter type.
public type(name: string, definition?: ParamTypeDefinition, definitionFn?: () => ParamTypeDefinition): ParamType | this
Parameters:
  • name - The type name
  • definition - The type definition (optional)
  • definitionFn - A function that returns a type definition to be merged with definition (optional)
Returns:
  • If only name is specified: the registered ParamType or undefined
  • If definition is specified: this (for chaining)
Note: Register custom types before using them in a state definition. Example:
// Encode object parameter as JSON string
urlService.config.type('myjson', {
  encode: (obj) => JSON.stringify(obj),
  decode: (str) => JSON.parse(str),
  is: (val) => typeof(val) === 'object',
  pattern: /[^/]+/,
  equals: (a, b) => _.isEqual(a, b),
});

Information Methods

These methods return information about the current location configuration:

baseHref()

Gets the base HREF.
public baseHref(): string
Returns: The application’s base href (e.g., http://localhost/approot/)

host()

Gets the host.
public host(): string
Returns: The host (e.g., localhost)

port()

Gets the port.
public port(): number
Returns: The port number (e.g., 80)

protocol()

Gets the protocol.
public protocol(): string
Returns: The protocol (e.g., http)

html5Mode()

Returns true when running in pushstate mode.
public html5Mode(): boolean
Returns: true when running in HTML5 mode (pushstate mode)

hashPrefix()

Gets or sets the hash prefix.
public hashPrefix(newprefix?: string): string
This only applies when not running in HTML5 mode (pushstate mode). Parameters:
  • newprefix - The new hash prefix (optional)
Returns: The current hash prefix (e.g., ! for hashbang URLs) Example:
// If the current url is http://localhost/app#!/uirouter/path/#anchor
urlService.config.hashPrefix(); // returns "!"

Build docs developers (and LLMs) love