/** * 配置小程序路由和分包配置 */ export type RouteRecord = { /** * @description 路由路径 URL */ url?: string; /** * @description 路由唯一标识 eg: Home, Logs 或者 分包别名 */ name?: string; /** * @description 路由别名名称 */ title?: string; /** * @description 是否 tabBar 路由页面 */ tabBar?: boolean; /** * @description 分包根目录 */ root?: string; /** * @description 分包路由配置 (分包页面路径,相对与分包根目录) */ pages?: RouteRecordPage[]; /** * @description 分包是否是独立分包 */ independent?: boolean; /** * @description 附加自定义数据 */ meta?: Record; }; export type RouteRecordName = string | symbol; export type RouteRecordPage = RouteRecord & Required>; export type SubRouteRecordPage = RouteRecord & Required>; /** * 配置小程序路由和分包配置 联合类型 */ export type RouteRecordRaw = RouteRecordPage | SubRouteRecordPage; /** * 路由 URL Query 参数 */ export type RouteQuery = Record; /** * 路由跳转参数 Option */ export type BaseRouteNavigateOption = { /** * @description 路由路径 URL */ url?: string; /** * @description 路由唯一标识 eg: Home, Logs */ name?: string; /** * @description 路由类型 navigateTo | switchTab | redirectTo | reLaunch */ type?: string; /** * @description 路由参数 eg: query: { a: 123 } */ query?: RouteQuery; }; /** * 当前小程序路由配置项 */ export type CurrentRouteNavigate = BaseRouteNavigateOption & { /** * 小程序路由 */ route?: string; /** * 小程序完整路由 */ fullPath?: string; }; /** * 继承 WechatMiniprogram.NavigateToOption 类型 */ export type RouteNavigateToOption = BaseRouteNavigateOption & Partial; /** * 继承 WechatMiniprogram.SwitchTabOption 类型 */ export type RouteSwitchTabOption = BaseRouteNavigateOption & Partial; /** * 继承 WechatMiniprogram.ReLaunchOption 类型 */ export type RouteReLaunchOption = BaseRouteNavigateOption & Partial; /** * 路由跳转参数集合 */ export type RouteNavigateOption = RouteNavigateToOption & RouteSwitchTabOption & RouteReLaunchOption; /** * 回调函数返回值 */ export type RouteNavigatCallbackResult = | WechatMiniprogram.NavigateToSuccessCallbackResult | WechatMiniprogram.GeneralCallbackResult; /** * 继承 WechatMiniprogram.NavigateBackOption 类型 */ export type RouteNavigateBackOption = { data?: Record; } & Partial; /** * Router instance */ export type Router = { /** * 路由配置项集合 */ routes: RouteRecordRaw[]; /** * 路由Map集合 */ matcher: Map>; /** * 获取当前路由页面的配置项 * * {@link CurrentRouteNavigate} */ getCurrentRoute: () => CurrentRouteNavigate; /** * 路由跳转 {@link RouteNavigateOption} * @description 内置小程序路由类型集合,解决页面层级超过 `10` 级无法跳转 * @param RouteNavigateOption | string */ go: (to: RouteNavigateOption | string) => Promise; /** * wx.navigateTo 路由跳转 * @description 继承小程序 `wx.navigateTo` 用法, 保留当前页面,跳转到应用内的某个页面。但是不能跳到 `tabbar` 页面 * @param RouteNavigateOption | string */ push(to: RouteNavigateOption | string): Promise; /** * wx.switchTab 路由跳转 * @description 继承小程序 `wx.switchTab` 用法,跳转到 `tabBar` 页面,并关闭其他所有非 `tabBar` 页面 * @param RouteNavigateOption | string */ tab(to: RouteNavigateOption | string): Promise; /** * wx.redirectTo 路由跳转 * @description 继承小程序 `wx.redirectTo` 用法,关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 `tabbar` 页面 * @param RouteNavigateOption | string */ replace(to: RouteNavigateOption | string): Promise; /** * wx.reLaunch 路由跳转 * @description 继承小程序 `wx.reLaunch` 用法,关闭所有页面,打开到应用内的某个页面 * @param RouteNavigateOption | string */ relaunch(navigate: RouteNavigateOption | string): Promise; /** * wx.navigateBack 路由跳转 * @description 继承小程序 `wx.navigateBack` 用法,关闭所有页面,打开到应用内的某个页面, 同时支持设置上一页面的数据 * @param data 设置上一页数据 */ back(to: RouteNavigateBackOption | number): Promise; };