UNPKG

5.59 kBTypeScriptView Raw
1import { Location } from '@angular/common';
2import { Type } from '../src/facade/lang';
3import { RouterOutlet } from './directives/router_outlet';
4import { Instruction } from './instruction';
5import { RouteDefinition } from './route_config/route_config_impl';
6import { RouteRegistry } from './route_registry';
7/**
8 * The `Router` is responsible for mapping URLs to components.
9 *
10 * You can see the state of the router by inspecting the read-only field `router.navigating`.
11 * This may be useful for showing a spinner, for instance.
12 *
13 * ## Concepts
14 *
15 * Routers and component instances have a 1:1 correspondence.
16 *
17 * The router holds reference to a number of {@link RouterOutlet}.
18 * An outlet is a placeholder that the router dynamically fills in depending on the current URL.
19 *
20 * When the router navigates from a URL, it must first recognize it and serialize it into an
21 * `Instruction`.
22 * The router uses the `RouteRegistry` to get an `Instruction`.
23 */
24export declare class Router {
25 registry: RouteRegistry;
26 parent: Router;
27 hostComponent: any;
28 root: Router;
29 navigating: boolean;
30 lastNavigationAttempt: string;
31 /**
32 * The current `Instruction` for the router
33 */
34 currentInstruction: Instruction;
35 private _currentNavigation;
36 private _outlet;
37 private _auxRouters;
38 private _childRouter;
39 private _subject;
40 constructor(registry: RouteRegistry, parent: Router, hostComponent: any, root?: Router);
41 /**
42 * Constructs a child router. You probably don't need to use this unless you're writing a reusable
43 * component.
44 */
45 childRouter(hostComponent: any): Router;
46 /**
47 * Constructs a child router. You probably don't need to use this unless you're writing a reusable
48 * component.
49 */
50 auxRouter(hostComponent: any): Router;
51 /**
52 * Register an outlet to be notified of primary route changes.
53 *
54 * You probably don't need to use this unless you're writing a reusable component.
55 */
56 registerPrimaryOutlet(outlet: RouterOutlet): Promise<any>;
57 /**
58 * Unregister an outlet (because it was destroyed, etc).
59 *
60 * You probably don't need to use this unless you're writing a custom outlet implementation.
61 */
62 unregisterPrimaryOutlet(outlet: RouterOutlet): void;
63 /**
64 * Register an outlet to notified of auxiliary route changes.
65 *
66 * You probably don't need to use this unless you're writing a reusable component.
67 */
68 registerAuxOutlet(outlet: RouterOutlet): Promise<any>;
69 /**
70 * Given an instruction, returns `true` if the instruction is currently active,
71 * otherwise `false`.
72 */
73 isRouteActive(instruction: Instruction): boolean;
74 /**
75 * Dynamically update the routing configuration and trigger a navigation.
76 *
77 * ### Usage
78 *
79 * ```
80 * router.config([
81 * { 'path': '/', 'component': IndexComp },
82 * { 'path': '/user/:id', 'component': UserComp },
83 * ]);
84 * ```
85 */
86 config(definitions: RouteDefinition[]): Promise<any>;
87 /**
88 * Navigate based on the provided Route Link DSL. It's preferred to navigate with this method
89 * over `navigateByUrl`.
90 *
91 * ### Usage
92 *
93 * This method takes an array representing the Route Link DSL:
94 * ```
95 * ['./MyCmp', {param: 3}]
96 * ```
97 * See the {@link RouterLink} directive for more.
98 */
99 navigate(linkParams: any[]): Promise<any>;
100 /**
101 * Navigate to a URL. Returns a promise that resolves when navigation is complete.
102 * It's preferred to navigate with `navigate` instead of this method, since URLs are more brittle.
103 *
104 * If the given URL begins with a `/`, router will navigate absolutely.
105 * If the given URL does not begin with `/`, the router will navigate relative to this component.
106 */
107 navigateByUrl(url: string, _skipLocationChange?: boolean): Promise<any>;
108 /**
109 * Navigate via the provided instruction. Returns a promise that resolves when navigation is
110 * complete.
111 */
112 navigateByInstruction(instruction: Instruction, _skipLocationChange?: boolean): Promise<any>;
113 private _emitNavigationFinish(instruction);
114 private _afterPromiseFinishNavigating(promise);
115 private _canActivate(nextInstruction);
116 private _routerCanDeactivate(instruction);
117 /**
118 * Updates this router and all descendant routers according to the given instruction
119 */
120 commit(instruction: Instruction, _skipLocationChange?: boolean): Promise<any>;
121 /**
122 * Subscribe to URL updates from the router
123 */
124 subscribe(onNext: (value: any) => void, onError?: (value: any) => void): Object;
125 /**
126 * Removes the contents of this router's outlet and all descendant outlets
127 */
128 deactivate(instruction: Instruction): Promise<any>;
129 /**
130 * Given a URL, returns an instruction representing the component graph
131 */
132 recognize(url: string): Promise<Instruction>;
133 private _getAncestorInstructions();
134 /**
135 * Navigates to either the last URL successfully navigated to, or the last URL requested if the
136 * router has yet to successfully navigate.
137 */
138 renavigate(): Promise<any>;
139 /**
140 * Generate an `Instruction` based on the provided Route Link DSL.
141 */
142 generate(linkParams: any[]): Instruction;
143}
144export declare class RootRouter extends Router {
145 constructor(registry: RouteRegistry, location: Location, primaryComponent: Type);
146 commit(instruction: Instruction, _skipLocationChange?: boolean): Promise<any>;
147 dispose(): void;
148}
149
\No newline at end of file