uni-simple-router.d.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. export declare interface AppConfig {
  2. registerLoadingPage?: boolean;
  3. loadingPageStyle?: () => object;
  4. loadingPageHook?: (view: any) => void;
  5. launchedHook?: () => void;
  6. animation?: startAnimationRule;
  7. }
  8. export declare interface appletConfig {
  9. animationDuration?: number;
  10. }
  11. export declare type backTypeRule = 'backbutton' | 'navigateBack';
  12. export declare function createRouter(params: InstantiateConfig): Router;
  13. export declare interface debuggerArrayConfig {
  14. error?: boolean;
  15. warn?: boolean;
  16. log?: boolean;
  17. }
  18. export declare type debuggerConfig = boolean | debuggerArrayConfig;
  19. export declare interface endAnimationRule {
  20. animationType?: endAnimationType;
  21. animationDuration?: number;
  22. }
  23. export declare type endAnimationType = 'slide-out-right' | 'slide-out-left' | 'slide-out-top' | 'slide-out-bottom' | 'pop-out' | 'fade-out' | 'zoom-in' | 'zoom-fade-in' | 'none';
  24. export declare type guardHookRule = (to: totalNextRoute, from: totalNextRoute, next: (rule?: navtoRule | false) => void) => void;
  25. export declare interface H5Config {
  26. paramsToQuery?: boolean;
  27. vueRouterDev?: boolean;
  28. vueNext?: boolean;
  29. mode?: string;
  30. base?: string;
  31. linkActiveClass?: string;
  32. linkExactActiveClass?: string;
  33. scrollBehavior?: Function;
  34. fallback?: boolean;
  35. }
  36. export declare interface h5NextRule {
  37. fullPath?: string | undefined;
  38. hash?: string | undefined;
  39. matched?: Array<object>;
  40. meta?: object;
  41. name?: undefined | string;
  42. type?: undefined | string;
  43. }
  44. export declare type hookListRule = Array<(router: Router, to: totalNextRoute, from: totalNextRoute, toRoute: RoutesRule, next: Function) => void>;
  45. export declare interface hookObjectRule {
  46. options: Array<any>;
  47. hook: Function;
  48. }
  49. declare type hookRule = (args: Array<any>, next: (args: Array<any>) => void, router: Router) => void;
  50. export declare enum hookToggle {
  51. 'beforeHooks' = "beforeEach",
  52. 'afterHooks' = "afterEach",
  53. 'enterHooks' = "beforeEnter"
  54. }
  55. export declare interface InstantiateConfig {
  56. [key: string]: any;
  57. keepUniOriginNav?: boolean;
  58. platform: platformRule;
  59. h5?: H5Config;
  60. APP?: AppConfig;
  61. applet?: appletConfig;
  62. beforeProxyHooks?: proxyHooksConfig;
  63. debugger?: debuggerConfig;
  64. routerBeforeEach?: (to: navtoRule, from: navtoRule, next: (rule?: navtoRule | false) => void) => void;
  65. routerAfterEach?: (to: navtoRule, from: navtoRule, next?: Function) => void;
  66. routerErrorEach?: (error: navErrorRule, router: Router) => void;
  67. resolveQuery?: (jsonQuery: objectAny) => objectAny;
  68. parseQuery?: (jsonQuery: objectAny) => objectAny;
  69. detectBeforeLock?: (router: Router, to: string | number | totalNextRoute | navRoute, navType: NAVTYPE) => void;
  70. routes: RoutesRule[];
  71. }
  72. export declare interface LifeCycleConfig {
  73. beforeHooks: hookListRule;
  74. afterHooks: hookListRule;
  75. routerBeforeHooks: hookListRule;
  76. routerAfterHooks: hookListRule;
  77. routerErrorHooks: Array<(error: navErrorRule, router: Router) => void>;
  78. }
  79. export declare interface navErrorRule {
  80. type: navRuleStatus;
  81. msg: string;
  82. to?: totalNextRoute;
  83. from?: totalNextRoute;
  84. nextTo?: any;
  85. [propName: string]: any;
  86. }
  87. export declare type navMethodRule = Promise<void | undefined | navRuleStatus>;
  88. export declare interface navRoute extends h5NextRule, navtoRule {
  89. }
  90. export declare type navRuleStatus = 0 | 1 | 2 | 3;
  91. export declare interface navtoRule {
  92. NAVTYPE?: NAVTYPE;
  93. path?: string;
  94. name?: string | undefined;
  95. query?: objectAny;
  96. params?: objectAny;
  97. animationType?: startAnimationType | endAnimationType;
  98. animationDuration?: number;
  99. events?: objectAny;
  100. success?: Function;
  101. fail?: Function;
  102. complete?: Function;
  103. }
  104. export declare type NAVTYPE = 'push' | 'replace' | 'replaceAll' | 'pushTab' | 'back';
  105. export declare enum navtypeToggle {
  106. 'push' = "navigateTo",
  107. 'replace' = "redirectTo",
  108. 'replaceAll' = "reLaunch",
  109. 'pushTab' = "switchTab",
  110. 'back' = "navigateBack"
  111. }
  112. export declare type objectAny = {
  113. [propName: string]: any;
  114. };
  115. export declare interface originMixins extends uniNavApiRule {
  116. BACKTYPE: '' | backTypeRule;
  117. }
  118. export declare type pageTypeRule = 'app' | 'page' | 'component';
  119. export declare type platformRule = 'h5' | 'app-plus' | 'app-lets' | 'mp-weixin' | 'mp-baidu' | 'mp-alipay' | 'mp-toutiao' | 'mp-qq' | 'mp-360';
  120. export declare type PromiseResolve = (value?: void | PromiseLike<void> | undefined) => void;
  121. export declare type proxyDepsRule = {
  122. resetIndex: Array<number>;
  123. hooks: {
  124. [key: number]: {
  125. proxyHook: () => void;
  126. callHook: (enterPath: string) => void;
  127. resetHook: () => void;
  128. };
  129. };
  130. options: {
  131. [key: number]: Array<any>;
  132. };
  133. };
  134. export declare type proxyHookName = 'beforeHooks' | 'afterHooks';
  135. export declare interface proxyHooksConfig {
  136. onLaunch?: hookRule;
  137. onShow?: hookRule;
  138. onHide?: hookRule;
  139. onError?: hookRule;
  140. onInit?: hookRule;
  141. onLoad?: hookRule;
  142. onReady?: hookRule;
  143. onUnload?: hookRule;
  144. onResize?: hookRule;
  145. destroyed?: hookRule;
  146. created?: hookRule;
  147. beforeCreate?: hookRule;
  148. beforeMount?: hookRule;
  149. mounted?: hookRule;
  150. beforeDestroy?: hookRule;
  151. }
  152. export declare type reloadNavRule = totalNextRoute | false | undefined | string;
  153. export declare type reNavMethodRule = 'navigateTo' | 'redirectTo' | 'reLaunch' | 'switchTab';
  154. export declare type reNotNavMethodRule = 'navigateBack';
  155. export declare enum rewriteMethodToggle {
  156. 'navigateTo' = "push",
  157. 'navigate' = "push",
  158. 'redirectTo' = "replace",
  159. 'reLaunch' = "replaceAll",
  160. 'switchTab' = "pushTab",
  161. 'navigateBack' = "back"
  162. }
  163. export declare interface Router {
  164. readonly lifeCycle: LifeCycleConfig;
  165. readonly options: InstantiateConfig;
  166. $lockStatus: boolean;
  167. $route: object | null;
  168. enterPath: string;
  169. runId: number;
  170. Vue: any;
  171. appMain: {
  172. NAVTYPE: reNavMethodRule | reNotNavMethodRule;
  173. path: string;
  174. } | {};
  175. proxyHookDeps: proxyDepsRule;
  176. routesMap: routesMapRule | {};
  177. mount: Array<{
  178. app: any;
  179. el: string;
  180. }>;
  181. install(Vue: any): void;
  182. push(to: totalNextRoute | navRoute | string, from?: totalNextRoute): void;
  183. replace(to: totalNextRoute | navRoute | string, from?: totalNextRoute): void;
  184. replaceAll(to: totalNextRoute | navRoute | string, from?: totalNextRoute): void;
  185. pushTab(to: totalNextRoute | navRoute | string, from?: totalNextRoute): void;
  186. back(level: number | undefined, origin?: uniBackRule | uniBackApiRule): void;
  187. forceGuardEach(navType: NAVTYPE | undefined, forceNav: boolean): void;
  188. beforeEach(userGuard: guardHookRule): void;
  189. afterEach(userGuard: (to: totalNextRoute, from: totalNextRoute) => void): void;
  190. }
  191. export declare function RouterMount(Vim: any, router: Router, el?: string | undefined): void | never;
  192. export declare interface routeRule {
  193. name: string | undefined;
  194. meta: objectAny;
  195. path: string;
  196. query: objectAny;
  197. params: objectAny;
  198. fullPath: string;
  199. NAVTYPE: NAVTYPE | '';
  200. BACKTYPE?: backTypeRule | '';
  201. [propName: string]: any;
  202. }
  203. export declare type routesMapKeysRule = 'finallyPathList' | 'finallyPathMap' | 'aliasPathMap' | 'pathMap' | 'nameMap' | 'vueRouteMap';
  204. export declare interface routesMapRule {
  205. [key: string]: any;
  206. finallyPathList: Array<string>;
  207. finallyPathMap: RoutesRule;
  208. aliasPathMap: RoutesRule;
  209. pathMap: RoutesRule;
  210. nameMap: RoutesRule;
  211. vueRouteMap: objectAny;
  212. }
  213. export declare interface RoutesRule {
  214. path: string;
  215. component?: object;
  216. name?: string;
  217. components?: object;
  218. redirect?: string | Function;
  219. props?: boolean | object | Function;
  220. aliasPath?: string;
  221. alias?: string | Array<string>;
  222. children?: Array<RoutesRule>;
  223. beforeEnter?: guardHookRule;
  224. meta?: any;
  225. [propName: string]: any;
  226. }
  227. export declare function runtimeQuit(title?: string | undefined): void;
  228. export declare interface startAnimationRule {
  229. animationType?: startAnimationType;
  230. animationDuration?: number;
  231. }
  232. export declare type startAnimationType = 'slide-in-right' | 'slide-in-left' | 'slide-in-top' | 'slide-in-bottom' | 'pop-in' | 'fade-in' | 'zoom-out' | 'zoom-fade-out' | 'none';
  233. export declare interface totalNextRoute extends h5NextRule, navtoRule {
  234. path: string;
  235. delta?: number;
  236. [propName: string]: any;
  237. }
  238. export declare interface uniBackApiRule {
  239. delta?: number;
  240. animationDuration?: number;
  241. animationType?: endAnimationType;
  242. }
  243. export declare interface uniBackRule {
  244. from: backTypeRule;
  245. }
  246. export declare interface uniNavApiRule {
  247. url: string;
  248. openType?: 'appLaunch';
  249. query?: objectAny;
  250. path?: string;
  251. delta?: number;
  252. detail?: {
  253. [propName: string]: any;
  254. };
  255. animationType?: startAnimationType;
  256. animationDuration?: number;
  257. events?: {
  258. [propName: string]: any;
  259. };
  260. success?: Function;
  261. fail?: Function;
  262. complete?: Function;
  263. animation?: {
  264. animationType?: startAnimationType;
  265. animationDuration?: number;
  266. };
  267. }
  268. export declare type vueHookNameRule = 'onLaunch' | 'onShow' | 'onHide' | 'onError' | 'onInit' | 'onLoad' | 'onReady' | 'onUnload' | 'onResize' | 'created' | 'beforeMount' | 'mounted' | 'beforeDestroy' | 'destroyed';
  269. export declare type vueOptionRule = {
  270. [propName in vueHookNameRule]: Array<Function> | undefined;
  271. };
  272. export { }
  273. // @ts-ignore
  274. declare module 'vue/types/vue' {
  275. interface Vue {
  276. $Router: Router;
  277. $Route: routeRule;
  278. }
  279. }