ExtraOptions interface

Represents options to configure the router.

Example

...
RouterModule.forRoot([
  // Routes definition
], {
  enableTracing: true,
}),

Options

enableTracing#

Makes the router log all its internal events to the console.

enableTracing?: boolean

useHash#

Enables the location strategy that uses the URL fragment instead of the history API.

useHash?: boolean

initialNavigation#

Disables the initial navigation.

initialNavigation?: InitialNavigation

errorHandler#

A custom error handler.

errorHandler?: ErrorHandler

preloadingStrategy#

Configures a preloading strategy.

preloadingStrategy?: any

onSameUrlNavigation#

Define what the router should do if it receives a navigation request to the current URL.

onSameUrlNavigation?: 'reload' | 'ignore'

By default, the router will ignore this navigation. However, this prevents features such as a "refresh" button. Use this option to configure the behavior when navigating to the current URL. Default is 'ignore'.

scrollPositionRestoration#

Configures if the scroll position needs to be restored when navigating back.

scrollPositionRestoration?: 'disabled' | 'enabled' | 'top'
  • disabled — does nothing (default).
  • top — set the scroll position to 0,0.
  • enabled — set the scroll position to the stored position. This option will be the default in the future.

When enabled, the router stores and restores scroll positions during navigation. When navigating forward, the scroll position will be set to [0, 0], or to the anchor if one is provided.

anchorScrolling#

Configures if the router should scroll to the element when the url has a fragment.

anchorScrolling?: 'disabled' | 'enabled'
  • disabled — does nothing (default).
  • enabled — scrolls to the element. This option will be the default in the future.

Anchor scrolling does not happen on popstate. Instead, we restore the position that we stored or scroll to the top.

scrollOffset#

Configures the scroll offset the router will use when scrolling to an element.

scrollOffset?: [number, number] | (() => [number, number])

When given a tuple with two numbers, the router will always use the numbers. When given a function, the router will invoke the function every time it restores scroll position.

paramsInheritanceStrategy#

Defines how the router merges params, data and resolved data from parent to child routes.

paramsInheritanceStrategy?: 'emptyOnly' | 'always'

Available options are:

  • emptyOnly — the default, only inherits parent params for path-less or component-less routes.
  • always — enables unconditional inheritance of parent params.

malformedUriErrorHandler#

A custom malformed uri error handler function. This handler is invoked when encodedURI contains invalid character sequences.

malformedUriErrorHandler?: (error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree

The default implementation is to redirect to the root url dropping any path or param info. This function passes three parameters:

  • URIError — Error thrown when parsing a bad URL
  • UrlSerializer — UrlSerializer that’s configured with the router.
  • url — The malformed URL that caused the URIError.

urlUpdateStrategy#

Defines when the router updates the browser URL.

urlUpdateStrategy?: 'deferred' | 'eager'

The default behavior is to update after successful navigation. However, some applications may prefer a mode where the URL gets updated at the beginning of navigation. The most common use case would be updating the URL early so if navigation fails, you can show an error message with the URL that failed. Available options are:

  • deferred — the default, updates the browser URL after navigation has finished.
  • eager — updates browser URL at the beginning of navigation.

relativeLinkResolution#

Enables a bug fix that corrects relative link resolution in components with empty paths.

relativeLinkResolution?: 'legacy' | 'corrected'

The current default in v6 is legacy, and this option will be removed in v7 to default to the corrected behavior.