ExtraOptions
interface
A set of configuration options for a router module, provided in the forRoot()
method.
interface ExtraOptions {
enableTracing?: boolean
useHash?: boolean
initialNavigation?: InitialNavigation
errorHandler?: ErrorHandler
preloadingStrategy?: any
onSameUrlNavigation?: 'reload' | 'ignore'
scrollPositionRestoration?: 'disabled' | 'enabled' | 'top'
anchorScrolling?: 'disabled' | 'enabled'
scrollOffset?: [number, number] | (() => [number, number])
paramsInheritanceStrategy?: 'emptyOnly' | 'always'
malformedUriErrorHandler?: (error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree
urlUpdateStrategy?: 'deferred' | 'eager'
relativeLinkResolution?: 'legacy' | 'corrected'
}
See also
forRoot()
Properties
Property | Description |
---|---|
enableTracing?: boolean
|
When true, log all internal navigation events to the console. Use for debugging. |
useHash?: boolean
|
When true, enable the location strategy that uses the URL fragment instead of the history API. |
initialNavigation?: InitialNavigation
|
One of enabled , enabledBlocking , enabledNonBlocking or disabled . When set to enabled or enabledBlocking , the initial navigation starts before the root component is created. The bootstrap is blocked until the initial navigation is complete. This value is required for server-side rendering to work. When set to enabledNonBlocking , the initial navigation starts after the root component has been created. The bootstrap is not blocked on the completion of the initial navigation. When set to disabled , the initial navigation is not performed. The location listener is set up before the root component gets created. Use if there is a reason to have more control over when the router starts its initial navigation due to some complex initialization logic.
|
errorHandler?: ErrorHandler
|
A custom error handler for failed navigations. If the handler returns a value, the navigation Promise is resolved with this value. If the handler throws an exception, the navigation Promise is rejected with the exception. |
preloadingStrategy?: any
|
Configures a preloading strategy. One of PreloadAllModules or NoPreloading (the default).
|
'ignore' | Define what the router should do if it receives a navigation request to the current URL. Default is ignore , which causes the router ignores the navigation. This can disable features such as a "refresh" button. Use this option to configure the behavior when navigating to the current URL. Default is 'ignore'.
|
'enabled' | 'top' |
Configures if the scroll position needs to be restored when navigating back.
You can implement custom scroll restoration behavior by adapting the enabled behavior as in the following example.
|
'enabled' |
When set to 'enabled', scrolls to the anchor element when the URL has a fragment. Anchor scrolling is disabled by default. Anchor scrolling does not happen on 'popstate'. Instead, we restore the position that we stored or scroll to the top. |
(() => [number, number]) |
Configures the scroll offset the router will use when scrolling to an element. When given a tuple with x and y position value, the router uses that offset each time it scrolls. When given a function, the router invokes the function every time it restores scroll position. |
'always' |
Defines how the router merges parameters, data, and resolved data from parent to child routes. By default ('emptyOnly'), inherits parent parameters only for path-less or component-less routes. Set to 'always' to enable unconditional inheritance of parent parameters. Note that when dealing with matrix parameters, "parent" refers to the parent |
malformedUriErrorHandler?: (error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree
|
A custom handler for malformed URI errors. The handler is invoked when
|
'eager' | Defines when the router updates the browser URL. By default ('deferred'), update after successful navigation. Set to 'eager' if prefer to update the URL at the beginning of navigation. Updating the URL early allows you to handle a failure of navigation by showing an error message with the URL that failed. |
'corrected' |
Enables a bug fix that corrects relative link resolution in components with empty paths. Example: const routes = [ { path: '', component: ContainerComponent, children: [ { path: 'a', component: AComponent }, { path: 'b', component: BComponent }, ] } ]; From the
However, this will work:
In other words, you're required to use The default in v11 is |
© 2010–2021 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/router/ExtraOptions