What it does
Provides the navigation and url manipulation capabilities.
See Routes
for more details and examples.
Class Overview
class Router {
constructor
(rootComponentType: Type<any>, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Routes)
errorHandler
: ErrorHandler
navigated
: boolean
urlHandlingStrategy
: UrlHandlingStrategy
routeReuseStrategy
: RouteReuseStrategy
config
: Routes
initialNavigation
() : void
setUpLocationChangeListener
() : void
routerState
: RouterState
url
: string
events
: Observable<Event>
resetConfig
(config: Routes) : void
ngOnDestroy
()
dispose
() : void
createUrlTree
(commands: any[], {relativeTo, queryParams, fragment, preserveQueryParams, queryParamsHandling,
}?: NavigationExtras) : UrlTree
navigateByUrl
(url: string|UrlTree, extras?: NavigationExtras) : Promise<boolean>
navigate
(commands: any[], extras?: NavigationExtras) : Promise<boolean>
serializeUrl
(url: UrlTree) : string
parseUrl
(url: string) : UrlTree
isActive
(url: string|UrlTree, exact: boolean) : boolean
}
Class Description
Constructor
Class Details
errorHandler : ErrorHandler
Error handler that is invoked when a navigation errors.
See ErrorHandler
for more information.
navigated : boolean
Indicates if at least one navigation happened.
urlHandlingStrategy : UrlHandlingStrategy
Extracts and merges URLs. Used for AngularJS to Angular migrations.
routeReuseStrategy : RouteReuseStrategy
config : Routes
initialNavigation() : void
Sets up the location change listener and performs the initial navigation.
setUpLocationChangeListener() : void
Sets up the location change listener.
routerState : RouterState
The current route state
url : string
The current url
events : Observable<Event>
An observable of router events
resetConfig(config: Routes) : void
Resets the configuration used for navigation and generating links.
Usage
ngOnDestroy()
dispose() : void
Disposes of the router
createUrlTree(commands: any[], {relativeTo, queryParams, fragment, preserveQueryParams, queryParamsHandling,
preserveFragment}?: NavigationExtras) : UrlTree
Applies an array of commands to the current url tree and creates a new url tree.
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
navigateByUrl(url: string|UrlTree, extras?: NavigationExtras) : Promise<boolean>
Navigate based on the provided url. This navigation is always absolute.
Returns a promise that:
- resolves to 'true' when navigation succeeds,
- resolves to 'false' when navigation fails,
- is rejected when an error happens.
Usage
In opposite to navigate
, navigateByUrl
takes a whole URL
and does not apply any delta to the current one.
navigate(commands: any[], extras?: NavigationExtras) : Promise<boolean>
Navigate based on the provided array of commands and a starting point. If no starting route is provided, the navigation is absolute.
Returns a promise that:
- resolves to 'true' when navigation succeeds,
- resolves to 'false' when navigation fails,
- is rejected when an error happens.
Usage
In opposite to navigateByUrl
, navigate
always takes a delta that is applied to the current
URL.
serializeUrl(url: UrlTree) : string
Serializes a UrlTree
into a string
parseUrl(url: string) : UrlTree
Parses a string into a UrlTree
isActive(url: string|UrlTree, exact: boolean) : boolean
Returns whether the url is activated
exported from router/index, defined in router/src/router.ts