UNPKG

32.8 kBTypeScriptView Raw
1import { Container } from 'aurelia-dependency-injection';
2import { EventAggregator } from 'aurelia-event-aggregator';
3import { History, NavigationOptions } from 'aurelia-history';
4
5/**
6* Class for storing and interacting with a route's navigation settings.
7*/
8export declare class NavModel {
9 /**
10 * True if this nav item is currently active.
11 */
12 isActive: boolean;
13 /**
14 * The title.
15 */
16 title: string;
17 /**
18 * This nav item's absolute href.
19 */
20 href: string;
21 /**
22 * This nav item's relative href.
23 */
24 relativeHref: string;
25 /**
26 * Data attached to the route at configuration time.
27 */
28 settings: any;
29 /**
30 * The route config.
31 */
32 config: RouteConfig;
33 /**
34 * The router associated with this navigation model.
35 */
36 router: Router;
37 order: number | boolean;
38 constructor(router: Router, relativeHref: string);
39 /**
40 * Sets the route's title and updates document.title.
41 * If the a navigation is in progress, the change will be applied
42 * to document.title when the navigation completes.
43 *
44 * @param title The new title.
45 */
46 setTitle(title: string): void;
47}
48/**
49 * Class used to configure a [[Router]] instance.
50 *
51 * @constructor
52 */
53export declare class RouterConfiguration {
54 instructions: Array<(router: Router) => void>;
55 options: {
56 [key: string]: any;
57 compareQueryParams?: boolean;
58 root?: string;
59 pushState?: boolean;
60 hashChange?: boolean;
61 silent?: boolean;
62 };
63 pipelineSteps: Array<{
64 name: string;
65 step: Function | PipelineStep;
66 }>;
67 title: string;
68 titleSeparator: string;
69 unknownRouteConfig: RouteConfigSpecifier;
70 viewPortDefaults: Record<string, any>;
71 /**
72 * Adds a step to be run during the [[Router]]'s navigation pipeline.
73 *
74 * @param name The name of the pipeline slot to insert the step into.
75 * @param step The pipeline step.
76 * @chainable
77 */
78 addPipelineStep(name: string, step: Function | PipelineStep): RouterConfiguration;
79 /**
80 * Adds a step to be run during the [[Router]]'s authorize pipeline slot.
81 *
82 * @param step The pipeline step.
83 * @chainable
84 */
85 addAuthorizeStep(step: Function | PipelineStep): RouterConfiguration;
86 /**
87 * Adds a step to be run during the [[Router]]'s preActivate pipeline slot.
88 *
89 * @param step The pipeline step.
90 * @chainable
91 */
92 addPreActivateStep(step: Function | PipelineStep): RouterConfiguration;
93 /**
94 * Adds a step to be run during the [[Router]]'s preRender pipeline slot.
95 *
96 * @param step The pipeline step.
97 * @chainable
98 */
99 addPreRenderStep(step: Function | PipelineStep): RouterConfiguration;
100 /**
101 * Adds a step to be run during the [[Router]]'s postRender pipeline slot.
102 *
103 * @param step The pipeline step.
104 * @chainable
105 */
106 addPostRenderStep(step: Function | PipelineStep): RouterConfiguration;
107 /**
108 * Configures a route that will be used if there is no previous location available on navigation cancellation.
109 *
110 * @param fragment The URL fragment to use as the navigation destination.
111 * @chainable
112 */
113 fallbackRoute(fragment: string): RouterConfiguration;
114 /**
115 * Maps one or more routes to be registered with the router.
116 *
117 * @param route The [[RouteConfig]] to map, or an array of [[RouteConfig]] to map.
118 * @chainable
119 */
120 map(route: RouteConfig | RouteConfig[]): RouterConfiguration;
121 /**
122 * Configures defaults to use for any view ports.
123 *
124 * @param viewPortConfig a view port configuration object to use as a
125 * default, of the form { viewPortName: { moduleId } }.
126 * @chainable
127 */
128 useViewPortDefaults(viewPortConfig: Record<string, {
129 [key: string]: any;
130 moduleId: string;
131 }>): RouterConfiguration;
132 /**
133 * Maps a single route to be registered with the router.
134 *
135 * @param route The [[RouteConfig]] to map.
136 * @chainable
137 */
138 mapRoute(config: RouteConfig): RouterConfiguration;
139 /**
140 * Registers an unknown route handler to be run when the URL fragment doesn't match any registered routes.
141 *
142 * @param config A string containing a moduleId to load, or a [[RouteConfig]], or a function that takes the
143 * [[NavigationInstruction]] and selects a moduleId to load.
144 * @chainable
145 */
146 mapUnknownRoutes(config: RouteConfigSpecifier): RouterConfiguration;
147 /**
148 * Applies the current configuration to the specified [[Router]].
149 *
150 * @param router The [[Router]] to apply the configuration to.
151 */
152 exportToRouter(router: Router): void;
153}
154/**
155 * The primary class responsible for handling routing and navigation.
156 */
157export declare class Router {
158 /**
159 * Container associated with this router. Also used to create child container for creating child router.
160 */
161 container: Container;
162 /**
163 * History instance of Aurelia abstract class for wrapping platform history global object
164 */
165 history: History;
166 /**
167 * A registry of registered viewport. Will be used to handle process navigation instruction route loading
168 * and dom swapping
169 */
170 viewPorts: Record<string, any>;
171 /**
172 * List of route configs registered with this router
173 */
174 routes: RouteConfig[];
175 /**
176 * The [[Router]]'s current base URL, typically based on the [[Router.currentInstruction]].
177 */
178 baseUrl: string;
179 /**
180 * If defined, used in generation of document title for [[Router]]'s routes.
181 */
182 title: string | undefined;
183 /**
184 * The separator used in the document title between [[Router]]'s routes.
185 */
186 titleSeparator: string | undefined;
187 /**
188 * True if the [[Router]] has been configured.
189 */
190 isConfigured: boolean;
191 /**
192 * True if the [[Router]] is currently processing a navigation.
193 */
194 isNavigating: boolean;
195 /**
196 * True if the [[Router]] is navigating due to explicit call to navigate function(s).
197 */
198 isExplicitNavigation: boolean;
199 /**
200 * True if the [[Router]] is navigating due to explicit call to navigateBack function.
201 */
202 isExplicitNavigationBack: boolean;
203 /**
204 * True if the [[Router]] is navigating into the app for the first time in the browser session.
205 */
206 isNavigatingFirst: boolean;
207 /**
208 * True if the [[Router]] is navigating to a page instance not in the browser session history.
209 */
210 isNavigatingNew: boolean;
211 /**
212 * True if the [[Router]] is navigating forward in the browser session history.
213 */
214 isNavigatingForward: boolean;
215 /**
216 * True if the [[Router]] is navigating back in the browser session history.
217 */
218 isNavigatingBack: boolean;
219 /**
220 * True if the [[Router]] is navigating due to a browser refresh.
221 */
222 isNavigatingRefresh: boolean;
223 /**
224 * True if the previous instruction successfully completed the CanDeactivatePreviousStep in the current navigation.
225 */
226 couldDeactivate: boolean;
227 /**
228 * The currently active navigation tracker.
229 */
230 currentNavigationTracker: number;
231 /**
232 * The navigation models for routes that specified [[RouteConfig.nav]].
233 */
234 navigation: NavModel[];
235 /**
236 * The currently active navigation instruction.
237 */
238 currentInstruction: NavigationInstruction;
239 /**
240 * The parent router, or null if this instance is not a child router.
241 */
242 parent: Router;
243 options: any;
244 /**
245 * The defaults used when a viewport lacks specified content
246 */
247 viewPortDefaults: Record<string, any>;
248 /**
249 * Extension point to transform the document title before it is built and displayed.
250 * By default, child routers delegate to the parent router, and the app router
251 * returns the title unchanged.
252 */
253 transformTitle: (title: string) => string;
254 /**
255 * @param container The [[Container]] to use when child routers.
256 * @param history The [[History]] implementation to delegate navigation requests to.
257 */
258 constructor(container: Container, history: History);
259 /**
260 * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.
261 * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.
262 */
263 reset(): void;
264 /**
265 * Gets a value indicating whether or not this [[Router]] is the root in the router tree. I.e., it has no parent.
266 */
267 readonly isRoot: boolean;
268 /**
269 * Registers a viewPort to be used as a rendering target for activated routes.
270 *
271 * @param viewPort The viewPort.
272 * @param name The name of the viewPort. 'default' if unspecified.
273 */
274 registerViewPort(viewPort: any, name?: string): void;
275 /**
276 * Returns a Promise that resolves when the router is configured.
277 */
278 ensureConfigured(): Promise<void>;
279 /**
280 * Configures the router.
281 *
282 * @param callbackOrConfig The [[RouterConfiguration]] or a callback that takes a [[RouterConfiguration]].
283 */
284 configure(callbackOrConfig: RouterConfiguration | ((config: RouterConfiguration) => RouterConfiguration)): Promise<void>;
285 /**
286 * Navigates to a new location.
287 *
288 * @param fragment The URL fragment to use as the navigation destination.
289 * @param options The navigation options.
290 */
291 navigate(fragment: string, options?: NavigationOptions): boolean;
292 /**
293 * Navigates to a new location corresponding to the route and params specified. Equivallent to [[Router.generate]] followed
294 * by [[Router.navigate]].
295 *
296 * @param route The name of the route to use when generating the navigation location.
297 * @param params The route parameters to be used when populating the route pattern.
298 * @param options The navigation options.
299 */
300 navigateToRoute(route: string, params?: any, options?: NavigationOptions): boolean;
301 /**
302 * Navigates back to the most recent location in history.
303 */
304 navigateBack(): void;
305 /**
306 * Creates a child router of the current router.
307 *
308 * @param container The [[Container]] to provide to the child router. Uses the current [[Router]]'s [[Container]] if unspecified.
309 * @returns {Router} The new child Router.
310 */
311 createChild(container?: Container): Router;
312 /**
313 * Generates a URL fragment matching the specified route pattern.
314 *
315 * @param name The name of the route whose pattern should be used to generate the fragment.
316 * @param params The route params to be used to populate the route pattern.
317 * @param options If options.absolute = true, then absolute url will be generated; otherwise, it will be relative url.
318 * @returns {string} A string containing the generated URL fragment.
319 */
320 generate(nameOrRoute: string | RouteConfig, params?: any, options?: any): string;
321 /**
322 * Creates a [[NavModel]] for the specified route config.
323 *
324 * @param config The route config.
325 */
326 createNavModel(config: RouteConfig): NavModel;
327 /**
328 * Registers a new route with the router.
329 *
330 * @param config The [[RouteConfig]].
331 * @param navModel The [[NavModel]] to use for the route. May be omitted for single-pattern routes.
332 */
333 addRoute(config: RouteConfig, navModel?: NavModel): void;
334 /**
335 * Gets a value indicating whether or not this [[Router]] or one of its ancestors has a route registered with the specified name.
336 *
337 * @param name The name of the route to check.
338 */
339 hasRoute(name: string): boolean;
340 /**
341 * Gets a value indicating whether or not this [[Router]] has a route registered with the specified name.
342 *
343 * @param name The name of the route to check.
344 */
345 hasOwnRoute(name: string): boolean;
346 /**
347 * Register a handler to use when the incoming URL fragment doesn't match any registered routes.
348 *
349 * @param config The moduleId, or a function that selects the moduleId, or a [[RouteConfig]].
350 */
351 handleUnknownRoutes(config?: RouteConfigSpecifier): void;
352 /**
353 * Updates the document title using the current navigation instruction.
354 */
355 updateTitle(): void;
356 /**
357 * Updates the navigation routes with hrefs relative to the current location.
358 * Note: This method will likely move to a plugin in a future release.
359 */
360 refreshNavigation(): void;
361 /**
362 * Sets the default configuration for the view ports. This specifies how to
363 * populate a view port for which no module is specified. The default is
364 * an empty view/view-model pair.
365 */
366 useViewPortDefaults($viewPortDefaults: Record<string, any>): void;
367}
368/**
369 * The strategy to use when activating modules during navigation.
370 */
371export declare const activationStrategy: ActivationStrategy;
372/**
373 * An optional interface describing the available activation strategies.
374 */
375export interface ActivationStrategy {
376 /**
377 * Reuse the existing view model, without invoking Router lifecycle hooks.
378 */
379 noChange: 'no-change';
380 /**
381 * Reuse the existing view model, invoking Router lifecycle hooks.
382 */
383 invokeLifecycle: 'invoke-lifecycle';
384 /**
385 * Replace the existing view model, invoking Router lifecycle hooks.
386 */
387 replace: 'replace';
388}
389/**
390 * Enum like type for activation strategy built-in values
391 */
392export declare type ActivationStrategyType = ActivationStrategy[keyof ActivationStrategy];
393/**
394 * Initialization options for a navigation instruction
395 */
396export interface NavigationInstructionInit {
397 fragment: string;
398 queryString?: string;
399 params?: Record<string, any>;
400 queryParams?: Record<string, any>;
401 config: RouteConfig;
402 parentInstruction?: NavigationInstruction;
403 previousInstruction?: NavigationInstruction;
404 router: Router;
405 options?: Object;
406 plan?: Record<string, /*ViewPortInstruction*/ any>;
407}
408export interface ViewPortInstructionInit {
409 name: string;
410 strategy: ActivationStrategyType;
411 moduleId: string;
412 component: ViewPortComponent;
413}
414/**
415 * Class used to represent an instruction during a navigation.
416 */
417export declare class NavigationInstruction {
418 /**
419 * The URL fragment.
420 */
421 fragment: string;
422 /**
423 * The query string.
424 */
425 queryString: string;
426 /**
427 * Parameters extracted from the route pattern.
428 */
429 params: any;
430 /**
431 * Parameters extracted from the query string.
432 */
433 queryParams: any;
434 /**
435 * The route config for the route matching this instruction.
436 */
437 config: RouteConfig;
438 /**
439 * The parent instruction, if this instruction was created by a child router.
440 */
441 parentInstruction: NavigationInstruction;
442 parentCatchHandler: any;
443 /**
444 * The instruction being replaced by this instruction in the current router.
445 */
446 previousInstruction: NavigationInstruction;
447 /**
448 * viewPort instructions to used activation.
449 */
450 viewPortInstructions: Record<string, /*ViewPortInstruction*/ any>;
451 /**
452 * The router instance.
453 */
454 router: Router;
455 /**
456 * Current built viewport plan of this nav instruction
457 */
458 plan: Record<string, /*ViewPortPlan*/ any>;
459 options: Record<string, any>;
460 constructor(init: NavigationInstructionInit);
461 /**
462 * Gets an array containing this instruction and all child instructions for the current navigation.
463 */
464 getAllInstructions(): Array<NavigationInstruction>;
465 /**
466 * Gets an array containing the instruction and all child instructions for the previous navigation.
467 * Previous instructions are no longer available after navigation completes.
468 */
469 getAllPreviousInstructions(): Array<NavigationInstruction>;
470 /**
471 * Adds a viewPort instruction. Returns the newly created instruction based on parameters
472 */
473 addViewPortInstruction(initOptions: ViewPortInstructionInit): any;
474 addViewPortInstruction(viewPortName: string, strategy: ActivationStrategyType, moduleId: string, component: any): any;
475 /**
476 * Gets the name of the route pattern's wildcard parameter, if applicable.
477 */
478 getWildCardName(): string;
479 /**
480 * Gets the path and query string created by filling the route
481 * pattern's wildcard parameter with the matching param.
482 */
483 getWildcardPath(): string;
484 /**
485 * Gets the instruction's base URL, accounting for wildcard route parameters.
486 */
487 getBaseUrl(): string;
488}
489/**
490* When a navigation command is encountered, the current navigation
491* will be cancelled and control will be passed to the navigation
492* command so it can determine the correct action.
493*/
494export interface NavigationCommand {
495 navigate: (router: Router) => void;
496}
497/**
498* Determines if the provided object is a navigation command.
499* A navigation command is anything with a navigate method.
500*
501* @param obj The object to check.
502*/
503export declare function isNavigationCommand(obj: any): obj is NavigationCommand;
504/**
505* Used during the activation lifecycle to cause a redirect.
506*/
507export declare class Redirect implements NavigationCommand {
508 url: string;
509 private router;
510 /**
511 * @param url The URL fragment to use as the navigation destination.
512 * @param options The navigation options.
513 */
514 constructor(url: string, options?: NavigationOptions);
515 /**
516 * Called by the activation system to set the child router.
517 *
518 * @param router The router.
519 */
520 setRouter(router: Router): void;
521 /**
522 * Called by the navigation pipeline to navigate.
523 *
524 * @param appRouter The router to be redirected.
525 */
526 navigate(appRouter: Router): void;
527}
528/**
529 * Used during the activation lifecycle to cause a redirect to a named route.
530 */
531export declare class RedirectToRoute implements NavigationCommand {
532 route: string;
533 params: any;
534 /**
535 * @param route The name of the route.
536 * @param params The parameters to be sent to the activation method.
537 * @param options The options to use for navigation.
538 */
539 constructor(route: string, params?: any, options?: NavigationOptions);
540 /**
541 * Called by the activation system to set the child router.
542 *
543 * @param router The router.
544 */
545 setRouter(router: Router): void;
546 /**
547 * Called by the navigation pipeline to navigate.
548 *
549 * @param appRouter The router to be redirected.
550 */
551 navigate(appRouter: Router): void;
552}
553/**
554 * A basic interface for an Observable type
555 */
556export interface IObservable {
557 subscribe(sub?: IObservableConfig): ISubscription;
558}
559export interface IObservableConfig {
560 next(): void;
561 error(err?: any): void;
562 complete(): void;
563}
564/**
565 * A basic interface for a Subscription to an Observable
566 */
567export interface ISubscription {
568 unsubscribe(): void;
569}
570/**
571* The status of a Pipeline.
572*/
573export declare const enum PipelineStatus {
574 Completed = "completed",
575 Canceled = "canceled",
576 Rejected = "rejected",
577 Running = "running"
578}
579/**
580 * A configuration object that describes a route for redirection
581 */
582export interface RedirectConfig {
583 /**
584 * path that will be redirected to. This is relative to currently in process router
585 */
586 redirect: string;
587 /**
588 * A backward compat interface. Should be ignored in new code
589 */
590 [key: string]: any;
591}
592/**
593 * A more generic RouteConfig for unknown route. Either a redirect config or a `RouteConfig`
594 * Redirect config is generally used in `mapUnknownRoutes` of `RouterConfiguration`
595 */
596export declare type RouteOrRedirectConfig = RouteConfig | RedirectConfig;
597/**
598 * A RouteConfig specifier. Could be a string, or an object with `RouteConfig` interface shape,
599 * or could be an object with redirect interface shape
600 */
601export declare type RouteConfigSpecifier = string | RouteOrRedirectConfig | ((instruction: NavigationInstruction) => string | RouteOrRedirectConfig | Promise<string | RouteOrRedirectConfig>);
602/**
603 * A configuration object that describes a route.
604 */
605export interface RouteConfig {
606 /**
607 * The route pattern to match against incoming URL fragments, or an array of patterns.
608 */
609 route: string | string[];
610 /**
611 * A unique name for the route that may be used to identify the route when generating URL fragments.
612 * Required when this route should support URL generation, such as with [[Router.generate]] or
613 * the route-href custom attribute.
614 */
615 name?: string;
616 /**
617 * The moduleId of the view model that should be activated for this route.
618 */
619 moduleId?: string;
620 /**
621 * A URL fragment to redirect to when this route is matched.
622 */
623 redirect?: string;
624 /**
625 * A function that can be used to dynamically select the module or modules to activate.
626 * The function is passed the current [[NavigationInstruction]], and should configure
627 * instruction.config with the desired moduleId, viewPorts, or redirect.
628 */
629 navigationStrategy?: (instruction: NavigationInstruction) => Promise<void> | void;
630 /**
631 * The view ports to target when activating this route. If unspecified, the target moduleId is loaded
632 * into the default viewPort (the viewPort with name 'default'). The viewPorts object should have keys
633 * whose property names correspond to names used by <router-view> elements. The values should be objects
634 * specifying the moduleId to load into that viewPort. The values may optionally include properties related to layout:
635 * `layoutView`, `layoutViewModel` and `layoutModel`.
636 */
637 viewPorts?: any;
638 /**
639 * When specified, this route will be included in the [[Router.navigation]] nav model. Useful for
640 * dynamically generating menus or other navigation elements. When a number is specified, that value
641 * will be used as a sort order.
642 */
643 nav?: boolean | number;
644 /**
645 * The URL fragment to use in nav models. If unspecified, the [[RouteConfig.route]] will be used.
646 * However, if the [[RouteConfig.route]] contains dynamic segments, this property must be specified.
647 */
648 href?: string;
649 /**
650 * Indicates that when route generation is done for this route, it should just take the literal value of the href property.
651 */
652 generationUsesHref?: boolean;
653 /**
654 * The document title to set when this route is active.
655 */
656 title?: string;
657 /**
658 * Arbitrary data to attach to the route. This can be used to attached custom data needed by components
659 * like pipeline steps and activated modules.
660 */
661 settings?: any;
662 /**
663 * The navigation model for storing and interacting with the route's navigation settings.
664 */
665 navModel?: NavModel;
666 /**
667 * When true is specified, this route will be case sensitive.
668 */
669 caseSensitive?: boolean;
670 /**
671 * Add to specify an activation strategy if it is always the same and you do not want that
672 * to be in your view-model code. Available values are 'replace' and 'invoke-lifecycle'.
673 */
674 activationStrategy?: ActivationStrategyType;
675 /**
676 * specifies the file name of a layout view to use.
677 */
678 layoutView?: string;
679 /**
680 * specifies the moduleId of the view model to use with the layout view.
681 */
682 layoutViewModel?: string;
683 /**
684 * specifies the model parameter to pass to the layout view model's `activate` function.
685 */
686 layoutModel?: any;
687 [x: string]: any;
688}
689/**
690 * An optional interface describing the canActivate convention.
691 */
692export interface RoutableComponentCanActivate {
693 /**
694 * Implement this hook if you want to control whether or not your view-model can be navigated to.
695 * Return a boolean value, a promise for a boolean value, or a navigation command.
696 */
697 canActivate(params: any, routeConfig: RouteConfig, navigationInstruction: NavigationInstruction): boolean | Promise<boolean> | PromiseLike<boolean> | NavigationCommand | Promise<NavigationCommand> | PromiseLike<NavigationCommand>;
698}
699/**
700 * An optional interface describing the activate convention.
701 */
702export interface RoutableComponentActivate {
703 /**
704 * Implement this hook if you want to perform custom logic just before your view-model is displayed.
705 * You can optionally return a promise to tell the router to wait to bind and attach the view until
706 * after you finish your work.
707 */
708 activate(params: any, routeConfig: RouteConfig, navigationInstruction: NavigationInstruction): Promise<void> | PromiseLike<void> | IObservable | void;
709}
710/**
711 * An optional interface describing the canDeactivate convention.
712 */
713export interface RoutableComponentCanDeactivate {
714 /**
715 * Implement this hook if you want to control whether or not the router can navigate away from your
716 * view-model when moving to a new route. Return a boolean value, a promise for a boolean value,
717 * or a navigation command.
718 */
719 canDeactivate: () => boolean | Promise<boolean> | PromiseLike<boolean> | NavigationCommand;
720}
721/**
722 * An optional interface describing the deactivate convention.
723 */
724export interface RoutableComponentDeactivate {
725 /**
726 * Implement this hook if you want to perform custom logic when your view-model is being
727 * navigated away from. You can optionally return a promise to tell the router to wait until
728 * after you finish your work.
729 */
730 deactivate: () => Promise<void> | PromiseLike<void> | IObservable | void;
731}
732/**
733 * An optional interface describing the determineActivationStrategy convention.
734 */
735export interface RoutableComponentDetermineActivationStrategy {
736 /**
737 * Implement this hook if you want to give hints to the router about the activation strategy, when reusing
738 * a view model for different routes. Available values are 'replace' and 'invoke-lifecycle'.
739 */
740 determineActivationStrategy(params: any, routeConfig: RouteConfig, navigationInstruction: NavigationInstruction): ActivationStrategyType;
741}
742/**
743 * An optional interface describing the router configuration convention.
744 */
745export interface ConfiguresRouter {
746 /**
747 * Implement this hook if you want to configure a router.
748 */
749 configureRouter(config: RouterConfiguration, router: Router): Promise<void> | PromiseLike<void> | void;
750}
751/**
752 * A step to be run during processing of the pipeline.
753 */
754export interface PipelineStep {
755 /**
756 * Execute the pipeline step. The step should invoke next(), next.complete(),
757 * next.cancel(), or next.reject() to allow the pipeline to continue.
758 *
759 * @param instruction The navigation instruction.
760 * @param next The next step in the pipeline.
761 */
762 run(instruction: NavigationInstruction, next: Next): Promise<any>;
763}
764/**
765 * A multi-step pipeline step that helps enable multiple hooks to the pipeline
766 */
767export interface IPipelineSlot {
768}
769/**
770 * The result of a pipeline run.
771 */
772export interface PipelineResult {
773 status: string;
774 instruction: NavigationInstruction;
775 output: any;
776 completed: boolean;
777}
778/**
779 * The component responsible for routing
780 */
781export interface ViewPortComponent {
782 viewModel: any;
783 childContainer?: Container;
784 router: Router;
785 config?: RouteConfig;
786 childRouter?: Router;
787 /**
788 * This is for backward compat, when moving from any to a more strongly typed interface
789 */
790 [key: string]: any;
791}
792export declare type NavigationResult = boolean | Promise<PipelineResult | boolean>;
793/**
794 * A callback to indicate when pipeline processing should advance to the next step
795 * or be aborted.
796 */
797export interface Next<T = any> {
798 /**
799 * Indicates the successful completion of the pipeline step.
800 */
801 (): Promise<any>;
802 /**
803 * Indicates the successful completion of the entire pipeline.
804 */
805 complete: NextCompletionHandler<T>;
806 /**
807 * Indicates that the pipeline should cancel processing.
808 */
809 cancel: NextCompletionHandler<T>;
810 /**
811 * Indicates that pipeline processing has failed and should be stopped.
812 */
813 reject: NextCompletionHandler<T>;
814}
815/**
816 * Next Completion result. Comprises of final status, output (could be value/error) and flag `completed`
817 */
818export interface NextCompletionResult<T = any> {
819 status: PipelineStatus;
820 output: T;
821 completed: boolean;
822}
823/**
824 * Handler for resolving `NextCompletionResult`
825 */
826export declare type NextCompletionHandler<T = any> = (output?: T) => Promise<NextCompletionResult<T>>;
827export declare type StepRunnerFunction = <TThis = any>(this: TThis, instruction: NavigationInstruction, next: Next) => any;
828/**
829 * The class responsible for managing and processing the navigation pipeline.
830 */
831export declare class Pipeline {
832 /**
833 * The pipeline steps. And steps added via addStep will be converted to a function
834 * The actualy running functions with correct step contexts of this pipeline
835 */
836 steps: StepRunnerFunction[];
837 /**
838 * Adds a step to the pipeline.
839 *
840 * @param step The pipeline step.
841 */
842 addStep(step: StepRunnerFunction | PipelineStep | IPipelineSlot): Pipeline;
843 /**
844 * Runs the pipeline.
845 *
846 * @param instruction The navigation instruction to process.
847 */
848 run(instruction: NavigationInstruction): Promise<PipelineResult>;
849}
850/**
851 * Class responsible for creating the navigation pipeline.
852 */
853export declare class PipelineProvider {
854 constructor(container: Container);
855 /**
856 * Create the navigation pipeline.
857 */
858 createPipeline(useCanDeactivateStep?: boolean): Pipeline;
859 /**
860 * Adds a step into the pipeline at a known slot location.
861 */
862 addStep(name: string, step: PipelineStep | Function): void;
863 /**
864 * Removes a step from a slot in the pipeline
865 */
866 removeStep(name: string, step: PipelineStep): void;
867 /**
868 * Resets all pipeline slots
869 */
870 reset(): void;
871}
872/**
873 * The main application router.
874 */
875export declare class AppRouter extends Router {
876 events: EventAggregator;
877 constructor(container: Container, history: History, pipelineProvider: PipelineProvider, events: EventAggregator);
878 /**
879 * Fully resets the router's internal state. Primarily used internally by the framework when multiple calls to setRoot are made.
880 * Use with caution (actually, avoid using this). Do not use this to simply change your navigation model.
881 */
882 reset(): void;
883 /**
884 * Loads the specified URL.
885 *
886 * @param url The URL fragment to load.
887 */
888 loadUrl(url: string): Promise<NavigationInstruction>;
889 /**
890 * Registers a viewPort to be used as a rendering target for activated routes.
891 *
892 * @param viewPort The viewPort. This is typically a <router-view/> element in Aurelia default impl
893 * @param name The name of the viewPort. 'default' if unspecified.
894 */
895 registerViewPort(viewPort: any, name?: string): Promise<any>;
896 /**
897 * Activates the router. This instructs the router to begin listening for history changes and processing instructions.
898 *
899 * @params options The set of options to activate the router with.
900 */
901 activate(options?: NavigationOptions): void;
902 /**
903 * Deactivates the router.
904 */
905 deactivate(): void;
906}
907/**
908 * A pipeline step responsible for finding and activating method `canDeactivate` on a view model of a route
909 */
910export declare class CanDeactivatePreviousStep {
911 run(navigationInstruction: NavigationInstruction, next: Next): Promise<any>;
912}
913/**
914 * A pipeline step responsible for finding and activating method `canActivate` on a view model of a route
915 */
916export declare class CanActivateNextStep {
917 run(navigationInstruction: NavigationInstruction, next: Next): Promise<any>;
918}
919/**
920 * A pipeline step responsible for finding and activating method `deactivate` on a view model of a route
921 */
922export declare class DeactivatePreviousStep {
923 run(navigationInstruction: NavigationInstruction, next: Next): Promise<any>;
924}
925/**
926 * A pipeline step responsible for finding and activating method `activate` on a view model of a route
927 */
928export declare class ActivateNextStep {
929 run(navigationInstruction: NavigationInstruction, next: Next): Promise<any>;
930}
931/**
932 * A pipeline step for instructing a piepline to commit changes on a navigation instruction
933 */
934export declare class CommitChangesStep {
935 run(navigationInstruction: NavigationInstruction, next: Function): Promise<any>;
936}
937/**
938 * Transform a navigation instruction into viewport plan record object,
939 * or a redirect request if user viewmodel demands
940 */
941export declare class BuildNavigationPlanStep {
942 run(navigationInstruction: NavigationInstruction, next: Next): Promise<any>;
943}
944/**
945 * Abstract class that is responsible for loading view / view model from a route config
946 * The default implementation can be found in `aurelia-templating-router`
947 */
948export declare class RouteLoader {
949 /**
950 * Load a route config based on its viewmodel / view configuration
951 */
952 loadRoute(router: Router, config: RouteConfig, navigationInstruction: NavigationInstruction): Promise</*ViewPortInstruction*/ any>;
953}
954/**
955 * A pipeline step responsible for loading a route config of a navigation instruction
956 */
957export declare class LoadRouteStep {
958 constructor(routeLoader: RouteLoader);
959 /**
960 * Run the internal to load route config of a navigation instruction to prepare for next steps in the pipeline
961 */
962 run(navigationInstruction: NavigationInstruction, next: Next): Promise<any>;
963}
964/**
965 * A list of known router events used by the Aurelia router
966 * to signal the pipeline has come to a certain state
967 */
968export declare const enum RouterEvent {
969 Processing = "router:navigation:processing",
970 Error = "router:navigation:error",
971 Canceled = "router:navigation:canceled",
972 Complete = "router:navigation:complete",
973 Success = "router:navigation:success",
974 ChildComplete = "router:navigation:child:complete"
975}
976/**
977 * Available pipeline slot names to insert interceptor into router pipeline
978 */
979export declare const enum PipelineSlotName {
980 /**
981 * Authorization slot. Invoked early in the pipeline,
982 * before `canActivate` hook of incoming route
983 */
984 Authorize = "authorize",
985 /**
986 * Pre-activation slot. Invoked early in the pipeline,
987 * Invoked timing:
988 * - after Authorization slot
989 * - after canActivate hook on new view model
990 * - before deactivate hook on old view model
991 * - before activate hook on new view model
992 */
993 PreActivate = "preActivate",
994 /**
995 * Pre-render slot. Invoked later in the pipeline
996 * Invokcation timing:
997 * - after activate hook on new view model
998 * - before commit step on new navigation instruction
999 */
1000 PreRender = "preRender",
1001 /**
1002 * Post-render slot. Invoked last in the pipeline
1003 */
1004 PostRender = "postRender"
1005}
\No newline at end of file