1 | /**
|
2 | * # URL subsystem
|
3 | *
|
4 | * Contains code related to managing the URL
|
5 | *
|
6 | * The primary API is found in [[UrlService]], [[UrlService.config]], and [[UrlService.rules]].
|
7 | *
|
8 | * @packageDocumentation
|
9 | * @preferred
|
10 | */
|
11 | import { LocationConfig } from '../common';
|
12 | import { UIRouter } from '../router';
|
13 | import { StateDeclaration, StateObject, TargetState, TargetStateDef } from '../state';
|
14 | import { UrlMatcher } from './urlMatcher';
|
15 | import { UrlConfig } from './urlConfig';
|
16 | import { UrlRules } from './urlRules';
|
17 | import { UrlService } from './urlService';
|
18 | export interface UrlMatcherCompileConfig {
|
19 | state?: StateDeclaration;
|
20 | strict?: boolean;
|
21 | caseInsensitive?: boolean;
|
22 | decodeParams?: boolean;
|
23 | }
|
24 | /** @deprecated use [[UrlConfig]] */
|
25 | export interface UrlConfigApi extends LocationConfig, UrlMatcherConfig {
|
26 | }
|
27 | /** @deprecated use [[UrlConfig]] */
|
28 | export interface UrlMatcherConfig {
|
29 | /** See: [[UrlConfig.caseInsensitive]] */ caseInsensitive: UrlConfig['caseInsensitive'];
|
30 | /** See: [[UrlConfig.strictMode]] */ strictMode: UrlConfig['strictMode'];
|
31 | /** See: [[UrlConfig.defaultSquashPolicy]] */ defaultSquashPolicy: UrlConfig['defaultSquashPolicy'];
|
32 | /** See: [[UrlConfig.type]] */ type: UrlConfig['type'];
|
33 | }
|
34 | /** @deprecated use [[UrlService]] */
|
35 | export interface UrlSyncApi {
|
36 | /** See: [[UrlService.sync]] */ sync: UrlService['sync'];
|
37 | /** See: [[UrlService.listen]] */ listen: UrlService['listen'];
|
38 | /** See: [[UrlService.deferIntercept]] */ deferIntercept: UrlService['deferIntercept'];
|
39 | }
|
40 | /** @deprecated use [[UrlRules]] */
|
41 | export interface UrlRulesApi {
|
42 | /** See: [[UrlRules.sort]] */ sort: UrlRules['sort'];
|
43 | /** See: [[UrlRules.when]] */ when: UrlRules['when'];
|
44 | /** See: [[UrlRules.otherwise]] */ otherwise: UrlRules['otherwise'];
|
45 | /** See: [[UrlRules.initial]] */ initial: UrlRules['initial'];
|
46 | /** See: [[UrlRules.rules]] */ rules: UrlRules['rules'];
|
47 | /** See: [[UrlRules.rule]] */ rule: UrlRules['rule'];
|
48 | /** See: [[UrlRules.removeRule]] */ removeRule: UrlRules['removeRule'];
|
49 | }
|
50 | /**
|
51 | * An object containing the three parts of a URL
|
52 | */
|
53 | export interface UrlParts {
|
54 | path: string;
|
55 | search?: {
|
56 | [key: string]: any;
|
57 | };
|
58 | hash?: string;
|
59 | }
|
60 | /**
|
61 | * A UrlRule match result
|
62 | *
|
63 | * The result of UrlRouter.match()
|
64 | */
|
65 | export interface MatchResult {
|
66 | /** The matched value from a [[UrlRule]] */
|
67 | match: any;
|
68 | /** The rule that matched */
|
69 | rule: UrlRule;
|
70 | /** The match result weight */
|
71 | weight: number;
|
72 | }
|
73 | /**
|
74 | * A function that matches the URL for a [[UrlRule]]
|
75 | *
|
76 | * Implementations should match against the provided [[UrlParts]] and return the matched value (truthy) if the rule matches.
|
77 | * If this rule is selected, the matched value is passed to the [[UrlRuleHandlerFn]].
|
78 | *
|
79 | * @return the matched value, either truthy or falsey
|
80 | */
|
81 | export interface UrlRuleMatchFn {
|
82 | (url?: UrlParts, router?: UIRouter): any;
|
83 | }
|
84 | /**
|
85 | * Handler invoked when a rule is matched
|
86 | *
|
87 | * The matched value from the rule's [[UrlRuleMatchFn]] is passed as the first argument
|
88 | * The handler should return a string (to redirect), a [[TargetState]]/[[TargetStateDef]], or void
|
89 | *
|
90 | * If the handler returns a string, the url is replaced with the string.
|
91 | * If the handler returns a [[TargetState]], the target state is activated.
|
92 | */
|
93 | export interface UrlRuleHandlerFn {
|
94 | (matchValue?: any, url?: UrlParts, router?: UIRouter): string | TargetState | TargetStateDef | void;
|
95 | }
|
96 | /** @internal */
|
97 | export declare type UrlRuleType = 'STATE' | 'URLMATCHER' | 'REGEXP' | 'RAW' | 'OTHER';
|
98 | /**
|
99 | * The interface for a URL Rule
|
100 | *
|
101 | * If you are creating a rule for use with [[UrlRules.rule]], it should implement this interface.
|
102 | */
|
103 | export interface UrlRule {
|
104 | /**
|
105 | * The rule's ID.
|
106 | *
|
107 | * IDs are auto-assigned when the rule is registered, in increasing order.
|
108 | */
|
109 | $id: number;
|
110 | /**
|
111 | * The rule's priority (defaults to 0).
|
112 | *
|
113 | * This can be used to explicitly modify the rule's priority.
|
114 | * Higher numbers are higher priority.
|
115 | */
|
116 | priority: number;
|
117 | /** @internal */
|
118 | _group: number;
|
119 | /** The type of the rule */
|
120 | type: UrlRuleType;
|
121 | /**
|
122 | * This function should match the url and return the match details
|
123 | *
|
124 | * See [[UrlRuleMatchFn]] for details
|
125 | */
|
126 | match: UrlRuleMatchFn;
|
127 | /**
|
128 | * This function is called if the rule matched, and was selected as the "best match".
|
129 | * This function handles the rule match event.
|
130 | *
|
131 | * See [[UrlRuleHandlerFn]] for details
|
132 | */
|
133 | handler: UrlRuleHandlerFn;
|
134 | /**
|
135 | * The priority of a given match.
|
136 | *
|
137 | * Sometimes more than one UrlRule might have matched.
|
138 | * This method is used to choose the best match.
|
139 | *
|
140 | * If multiple rules matched, each rule's `matchPriority` is called with the value from [[match]].
|
141 | * The rule with the highest `matchPriority` has its [[handler]] called.
|
142 | */
|
143 | matchPriority(match: any): number;
|
144 | }
|
145 | export interface MatcherUrlRule extends UrlRule {
|
146 | type: 'URLMATCHER' | 'STATE';
|
147 | urlMatcher: UrlMatcher;
|
148 | }
|
149 | export interface StateRule extends MatcherUrlRule {
|
150 | type: 'STATE';
|
151 | state: StateObject;
|
152 | }
|
153 | export interface RegExpRule extends UrlRule {
|
154 | type: 'REGEXP';
|
155 | regexp: RegExp;
|
156 | }
|