angular-cn/public/docs/js/latest/api/router/Router-class.jade

270 lines
3.4 KiB
Plaintext

p.location-badge.
exported from <a href="/angular2/router.html">angular2/router</a>
defined in <a href="https://github.com/angular/angular/tree/master/modules/angular2/src/router/router.js#L18">angular2/src/router/router.js (line 18)</a>
:markdown
## Router
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.
.l-main-section
h2 Members
.l-sub-section
h3 constructor
pre.prettyprint
code.
constructor(registry:RouteRegistry, pipeline:Pipeline, parent:Router = null, name = &#39;/&#39;)
:markdown
.l-sub-section
h3 activateOutlets
pre.prettyprint
code.
activateOutlets(instruction:Instruction)
:markdown
.l-sub-section
h3 childRouter
pre.prettyprint
code.
childRouter(outletName = &#39;default&#39;)
:markdown
Constructs a child router. You probably don't need to use this unless you're writing a reusable component.
.l-sub-section
h3 config
pre.prettyprint
code.
config(path:string, component, alias:string=null)
:markdown
Update the routing configuration and trigger a navigation.
### Usage
```
router.config('/', SomeCmp);
```
.l-sub-section
h3 generate
pre.prettyprint
code.
generate(name:string, params:any)
:markdown
Generate a URL from a component name and optional map of parameters. The URL is relative to the app's base href.
.l-sub-section
h3 getRoot
pre.prettyprint
code.
getRoot()
:markdown
.l-sub-section
h3 lastNavigationAttempt
:markdown
.l-sub-section
h3 name
:markdown
.l-sub-section
h3 navigate
pre.prettyprint
code.
navigate(url:string)
:markdown
Navigate to a URL. Returns a promise that resolves to the canonical URL for the route.
.l-sub-section
h3 navigating
:markdown
.l-sub-section
h3 parent
:markdown
.l-sub-section
h3 previousUrl
:markdown
.l-sub-section
h3 recognize
pre.prettyprint
code.
recognize(url:string)
:markdown
Given a URL, returns an instruction representing the component graph
.l-sub-section
h3 registerOutlet
pre.prettyprint
code.
registerOutlet(outlet:RouterOutlet, name = &#39;default&#39;)
:markdown
Register an object to notify of route changes. You probably don't need to use this unless you're writing a reusable component.
.l-sub-section
h3 renavigate
pre.prettyprint
code.
renavigate()
:markdown
Navigates to either the last URL successfully navigated to, or the last URL requested if the router has yet to successfully navigate.
.l-sub-section
h3 subscribe
pre.prettyprint
code.
subscribe(onNext)
:markdown
Subscribe to URL updates from the router
.l-sub-section
h3 traverseOutlets
pre.prettyprint
code.
traverseOutlets(fn)
:markdown