export class Router
export class Router
exported from angular2/router defined in angular2/src/router/router.ts (line 18)
The Router
is responsible for mapping URLs to components.
You can see the state of the router by inspecting the read-only field router.navigating
.
This may be useful for showing a spinner, for instance.
Concepts
Routers and component instances have a 1:1 correspondence.
The router holds reference to a number of RouterOutlet
.
An outlet is a placeholder that the router dynamically fills in depending on the current URL.
When the router navigates from a URL, it must first recognize it and serialize it into an
Instruction
.
The router uses the RouteRegistry
to get an Instruction
.
Constructor
constructor(registry: RouteRegistry, parent: Router, hostComponent: any)
constructor(registry: RouteRegistry, parent: Router, hostComponent: any)
Not Yet Documented
Members
navigating : boolean
navigating : boolean
Not Yet Documented
lastNavigationAttempt : string
lastNavigationAttempt : string
Not Yet Documented
registry : RouteRegistry
registry : RouteRegistry
Not Yet Documented
parent : Router
parent : Router
Not Yet Documented
hostComponent : any
hostComponent : any
Not Yet Documented
childRouter(hostComponent: any) : Router
childRouter(hostComponent: any) : Router
Constructs a child router. You probably don't need to use this unless you're writing a reusable component.
auxRouter(hostComponent: any) : Router
auxRouter(hostComponent: any) : Router
Constructs a child router. You probably don't need to use this unless you're writing a reusable component.
registerPrimaryOutlet(outlet: RouterOutlet) : Promise<boolean>
registerPrimaryOutlet(outlet: RouterOutlet) : Promise<boolean>
Register an outlet to be notified of primary route changes.
You probably don't need to use this unless you're writing a reusable component.
registerAuxOutlet(outlet: RouterOutlet) : Promise<boolean>
registerAuxOutlet(outlet: RouterOutlet) : Promise<boolean>
Register an outlet to notified of auxiliary route changes.
You probably don't need to use this unless you're writing a reusable component.
isRouteActive(instruction: Instruction) : boolean
isRouteActive(instruction: Instruction) : boolean
Given an instruction, returns true
if the instruction is currently active,
otherwise false
.
config(definitions: RouteDefinition[]) : Promise<any>
config(definitions: RouteDefinition[]) : Promise<any>
Dynamically update the routing configuration and trigger a navigation.
Usage
navigate(linkParams: any[]) : Promise<any>
navigate(linkParams: any[]) : Promise<any>
Navigate based on the provided Route Link DSL. It's preferred to navigate with this method
over navigateByUrl
.
Usage
This method takes an array representing the Route Link DSL:
See the RouterLink
directive for more.
navigateByUrl(url: string, _skipLocationChange?: boolean) : Promise<any>
navigateByUrl(url: string, _skipLocationChange?: boolean) : Promise<any>
Navigate to a URL. Returns a promise that resolves when navigation is complete.
It's preferred to navigate with navigate
instead of this method, since URLs are more brittle.
If the given URL begins with a /
, router will navigate absolutely.
If the given URL does not begin with /
, the router will navigate relative to this component.
navigateByInstruction(instruction: Instruction, _skipLocationChange?: boolean) : Promise<any>
navigateByInstruction(instruction: Instruction, _skipLocationChange?: boolean) : Promise<any>
Navigate via the provided instruction. Returns a promise that resolves when navigation is complete.
commit(instruction: Instruction, _skipLocationChange?: boolean) : Promise<any>
commit(instruction: Instruction, _skipLocationChange?: boolean) : Promise<any>
Updates this router and all descendant routers according to the given instruction
subscribe(onNext: (value: any) => void) : Object
subscribe(onNext: (value: any) => void) : Object
Subscribe to URL updates from the router
deactivate(instruction: Instruction) : Promise<any>
deactivate(instruction: Instruction) : Promise<any>
Removes the contents of this router's outlet and all descendant outlets
recognize(url: string) : Promise<Instruction>
recognize(url: string) : Promise<Instruction>
Given a URL, returns an instruction representing the component graph
renavigate() : Promise<any>
renavigate() : Promise<any>
Navigates to either the last URL successfully navigated to, or the last URL requested if the router has yet to successfully navigate.
generate(linkParams: any[]) : Instruction
generate(linkParams: any[]) : Instruction
Generate an Instruction
based on the provided Route Link DSL.