Router
An NgModule that provides navigation and URL manipulation capabilities.
class Router {
constructor(rootComponentType: Type<any>, urlSerializer: UrlSerializer, rootContexts: ChildrenOutletContexts, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Route[])
events: Observable<Event>
routerState: RouterState
errorHandler: ErrorHandler
malformedUriErrorHandler: (error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree
navigated: boolean
urlHandlingStrategy: UrlHandlingStrategy
routeReuseStrategy: RouteReuseStrategy
onSameUrlNavigation: 'reload' | 'ignore'
paramsInheritanceStrategy: 'emptyOnly' | 'always'
urlUpdateStrategy: 'deferred' | 'eager'
relativeLinkResolution: 'legacy' | 'corrected'
config: Routes
url: string
initialNavigation(): void
setUpLocationChangeListener(): void
getCurrentNavigation(): Navigation | null
resetConfig(config: Route[]): void
ngOnDestroy(): void
dispose(): void
createUrlTree(commands: any[], navigationExtras: NavigationExtras = {}): UrlTree
navigateByUrl(url: string | UrlTree, extras: NavigationExtras = { skipLocationChange: false }): Promise<boolean>
navigate(commands: any[], extras: NavigationExtras = { skipLocationChange: false }): Promise<boolean>
serializeUrl(url: UrlTree): string
parseUrl(url: string): UrlTree
isActive(url: string | UrlTree, exact: boolean): boolean
}
See also
Constructor
Creates the router service. |
||||||||||||||||||||||||
Parameters
|
Properties
Property | Description |
---|---|
events: Observable<Event>
|
Read-only.
An event stream for routing events in this NgModule. |
routerState: RouterState
|
Read-only.
The current state of routing in this NgModule. |
errorHandler: ErrorHandler
|
A handler for navigation errors in this NgModule. |
malformedUriErrorHandler: (error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree
|
Malformed uri error handler is invoked when |
navigated: boolean
|
True if at least one navigation event has occurred, false otherwise. |
urlHandlingStrategy: UrlHandlingStrategy
|
Extracts and merges URLs. Used for AngularJS to Angular migrations. |
routeReuseStrategy: RouteReuseStrategy
|
The strategy for re-using routes. |
onSameUrlNavigation: 'reload' | 'ignore'
|
How to handle a navigation request to the current URL. One of:
|
paramsInheritanceStrategy: 'emptyOnly' | 'always'
|
How to merge parameters, data, and resolved data from parent to child routes. One of:
|
urlUpdateStrategy: 'deferred' | 'eager'
|
Defines when the router updates the browser URL. 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:
|
relativeLinkResolution: 'legacy' | 'corrected'
|
See |
config: Routes
|
Declared in constructor. |
url: string
|
Read-only.
The current URL. |
Methods
Sets up the location change listener and performs the initial navigation. |
Sets up the location change listener. |
ParametersThere are no parameters. Returns
|
The current Navigation object if one exists |
ParametersThere are no parameters. Returns
|
Resets the configuration used for navigation and generating links. |
Usage Notes
|
ParametersThere are no parameters. Returns
|
Disposes of the router. |
ParametersThere are no parameters. Returns
|
Applies an array of commands to the current URL tree and creates a new URL tree. |
||||||
Parameters
Returns
|
||||||
When given an activate route, applies the given commands starting from the route. When not given a route, applies the given command starting from the root. |
||||||
Usage Notes
|
Navigate based on the provided URL, which must be absolute. |
||||||
Parameters
Returns
|
||||||
Usage NotesExample
|
Navigate based on the provided array of commands and a starting point. If no starting route is provided, the navigation is absolute. |
||||||
Parameters
Returns
|
||||||
Returns a promise that:
|
||||||
Usage NotesExample
The first parameter of In order to affect this browser's |
Serializes a |
Parses a string into a |
Returns whether the url is activated |