Router
A service that provides navigation among views and URL manipulation capabilities.
class Router {
events: Observable<Event>
routerState
errorHandler: (error: any) => any
navigated: boolean
routeReuseStrategy: RouteReuseStrategy
onSameUrlNavigation: OnSameUrlNavigation
config: Routes
componentInputBindingEnabled: boolean
url: string
lastSuccessfulNavigation: Navigation | null
initialNavigation(): void
setUpLocationChangeListener(): void
getCurrentNavigation(): Navigation | null
resetConfig(config: Routes): void
dispose(): void
createUrlTree(commands: any[], navigationExtras: UrlCreationOptions = {}): UrlTree
navigateByUrl(url: string | UrlTree, extras: NavigationBehaviorOptions = {...}): Promise<boolean>
navigate(commands: any[], extras: NavigationExtras = { skipLocationChange: false }): Promise<boolean>
serializeUrl(url: UrlTree): string
parseUrl(url: string): UrlTree
isActive(url: string | UrlTree, matchOptions: boolean | IsActiveMatchOptions): boolean
isActive(url: string | UrlTree, exact: boolean): boolean
isActive(url: string | UrlTree, matchOptions: IsActiveMatchOptions): boolean
isActive(url: string | UrlTree, matchOptions: boolean | IsActiveMatchOptions): boolean
}
See also
Provided in
-
RouterModule
-
'root'
Properties
Property | Description |
---|---|
events: Observable<Event>
|
Read-Only
An event stream for routing events. |
routerState
|
Read-Only
The current state of routing in this NgModule. |
errorHandler: (error: any) => any
|
A handler for navigation errors in this NgModule. Deprecated Subscribe to the See also: |
navigated: boolean
|
True if at least one navigation event has occurred, false otherwise. |
routeReuseStrategy: RouteReuseStrategy
|
A strategy for re-using routes. Deprecated Configure using |
onSameUrlNavigation: OnSameUrlNavigation
|
How to handle a navigation request to the current URL. Deprecated Configure this through See also: |
config: Routes
|
|
componentInputBindingEnabled: boolean
|
Read-Only
Indicates whether the application has opted in to binding Router data to component inputs. This option is enabled by the |
url: string
|
Read-Only
The current URL. |
lastSuccessfulNavigation: Navigation | null
|
Read-Only
The |
Methods
initialNavigation() |
---|
Sets up the location change listener and performs the initial navigation. |
ParametersThere are no parameters. Returns
|
setUpLocationChangeListener() |
---|
Sets up the location change listener. This listener detects navigations triggered from outside the Router (the browser back/forward buttons, for example) and schedules a corresponding Router navigation so that the correct events, guards, etc. are triggered. |
ParametersThere are no parameters. Returns
|
getCurrentNavigation() |
---|
Returns the current |
ParametersThere are no parameters. Returns
|
resetConfig() |
---|
Resets the route configuration used for navigation and generating links. |
Usage Notes
|
dispose() |
---|
Disposes of the router. |
ParametersThere are no parameters. Returns
|
createUrlTree() | ||||||
---|---|---|---|---|---|---|
Appends URL segments to the current URL tree to create a new URL tree. |
||||||
Parameters
Returns
|
||||||
Usage Notes
|
navigateByUrl() | ||||||
---|---|---|---|---|---|---|
Navigates to a view using an absolute route path. See also: |
||||||
Parameters
Returns
|
||||||
Usage NotesThe following calls request navigation to an absolute path.
|
navigate() | ||||||
---|---|---|---|---|---|---|
Navigate based on the provided array of commands and a starting point. If no starting route is provided, the navigation is absolute. See also: |
||||||
Parameters
Returns
|
||||||
Usage NotesThe following calls request navigation to a dynamic route path relative to the current URL.
|
serializeUrl() |
---|
Serializes a |
parseUrl() |
---|
Parses a string into a |
isActive() | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
url
|
string | UrlTree |
|
exact
|
boolean |
Returns
boolean
Overload #2
Returns whether the url is activated.
isActive(url: string | UrlTree, matchOptions: IsActiveMatchOptions): boolean
Parameters
url
|
string | UrlTree |
|
matchOptions
|
IsActiveMatchOptions |
Returns
boolean
Overload #3
isActive(url: string | UrlTree, matchOptions: boolean | IsActiveMatchOptions): boolean
Parameters
url
|
string | UrlTree |
|
matchOptions
|
boolean | IsActiveMatchOptions |
Returns
boolean