UNPKG

6.08 kBTypeScriptView Raw
1/** @publicapi @module url */ /** */
2import { UIRouter, LocationServices, $InjectorLike, UrlRuleHandlerFn, UrlMatcher, IInjectable, UrlRouter } from '@uirouter/core';
3export interface RawNg1RuleFunction {
4 ($injector: $InjectorLike, $location: LocationServices): string | void;
5}
6/**
7 * Manages rules for client-side URL
8 *
9 * ### Deprecation warning:
10 * This class is now considered to be an internal API
11 * Use the [[UrlService]] instead.
12 * For configuring URL rules, use the [[UrlRulesApi]] which can be found as [[UrlService.rules]].
13 *
14 * This class manages the router rules for what to do when the URL changes.
15 *
16 * This provider remains for backwards compatibility.
17 *
18 * @internalapi
19 * @deprecated
20 */
21export declare class UrlRouterProvider {
22 private router;
23 static injectableHandler(router: UIRouter, handler: IInjectable): UrlRuleHandlerFn;
24 /** @hidden */
25 constructor(/** @hidden */ router: UIRouter);
26 /** @hidden */
27 $get(): UrlRouter;
28 /**
29 * Registers a url handler function.
30 *
31 * Registers a low level url handler (a `rule`).
32 * A rule detects specific URL patterns and returns a redirect, or performs some action.
33 *
34 * If a rule returns a string, the URL is replaced with the string, and all rules are fired again.
35 *
36 * #### Example:
37 * ```js
38 * var app = angular.module('app', ['ui.router.router']);
39 *
40 * app.config(function ($urlRouterProvider) {
41 * // Here's an example of how you might allow case insensitive urls
42 * $urlRouterProvider.rule(function ($injector, $location) {
43 * var path = $location.path(),
44 * normalized = path.toLowerCase();
45 *
46 * if (path !== normalized) {
47 * return normalized;
48 * }
49 * });
50 * });
51 * ```
52 *
53 * @param ruleFn
54 * Handler function that takes `$injector` and `$location` services as arguments.
55 * You can use them to detect a url and return a different url as a string.
56 *
57 * @return [[UrlRouterProvider]] (`this`)
58 */
59 rule(ruleFn: RawNg1RuleFunction): UrlRouterProvider;
60 /**
61 * Defines the path or behavior to use when no url can be matched.
62 *
63 * #### Example:
64 * ```js
65 * var app = angular.module('app', ['ui.router.router']);
66 *
67 * app.config(function ($urlRouterProvider) {
68 * // if the path doesn't match any of the urls you configured
69 * // otherwise will take care of routing the user to the
70 * // specified url
71 * $urlRouterProvider.otherwise('/index');
72 *
73 * // Example of using function rule as param
74 * $urlRouterProvider.otherwise(function ($injector, $location) {
75 * return '/a/valid/url';
76 * });
77 * });
78 * ```
79 *
80 * @param rule
81 * The url path you want to redirect to or a function rule that returns the url path or performs a `$state.go()`.
82 * The function version is passed two params: `$injector` and `$location` services, and should return a url string.
83 *
84 * @return {object} `$urlRouterProvider` - `$urlRouterProvider` instance
85 */
86 otherwise(rule: string | RawNg1RuleFunction): UrlRouterProvider;
87 /**
88 * Registers a handler for a given url matching.
89 *
90 * If the handler is a string, it is
91 * treated as a redirect, and is interpolated according to the syntax of match
92 * (i.e. like `String.replace()` for `RegExp`, or like a `UrlMatcher` pattern otherwise).
93 *
94 * If the handler is a function, it is injectable.
95 * It gets invoked if `$location` matches.
96 * You have the option of inject the match object as `$match`.
97 *
98 * The handler can return
99 *
100 * - **falsy** to indicate that the rule didn't match after all, then `$urlRouter`
101 * will continue trying to find another one that matches.
102 * - **string** which is treated as a redirect and passed to `$location.url()`
103 * - **void** or any **truthy** value tells `$urlRouter` that the url was handled.
104 *
105 * #### Example:
106 * ```js
107 * var app = angular.module('app', ['ui.router.router']);
108 *
109 * app.config(function ($urlRouterProvider) {
110 * $urlRouterProvider.when($state.url, function ($match, $stateParams) {
111 * if ($state.$current.navigable !== state ||
112 * !equalForKeys($match, $stateParams) {
113 * $state.transitionTo(state, $match, false);
114 * }
115 * });
116 * });
117 * ```
118 *
119 * @param what A pattern string to match, compiled as a [[UrlMatcher]].
120 * @param handler The path (or function that returns a path) that you want to redirect your user to.
121 * @param ruleCallback [optional] A callback that receives the `rule` registered with [[UrlMatcher.rule]]
122 *
123 * Note: the handler may also invoke arbitrary code, such as `$state.go()`
124 */
125 when(what: RegExp | UrlMatcher | string, handler: string | IInjectable): this;
126 /**
127 * Disables monitoring of the URL.
128 *
129 * Call this method before UI-Router has bootstrapped.
130 * It will stop UI-Router from performing the initial url sync.
131 *
132 * This can be useful to perform some asynchronous initialization before the router starts.
133 * Once the initialization is complete, call [[listen]] to tell UI-Router to start watching and synchronizing the URL.
134 *
135 * #### Example:
136 * ```js
137 * var app = angular.module('app', ['ui.router']);
138 *
139 * app.config(function ($urlRouterProvider) {
140 * // Prevent $urlRouter from automatically intercepting URL changes;
141 * $urlRouterProvider.deferIntercept();
142 * })
143 *
144 * app.run(function (MyService, $urlRouter, $http) {
145 * $http.get("/stuff").then(function(resp) {
146 * MyService.doStuff(resp.data);
147 * $urlRouter.listen();
148 * $urlRouter.sync();
149 * });
150 * });
151 * ```
152 *
153 * @param defer Indicates whether to defer location change interception.
154 * Passing no parameter is equivalent to `true`.
155 */
156 deferIntercept(defer?: boolean): void;
157}