Wevu Router 类型
以下类型均从 wevu/router 导出。运行时函数和 Router 实例方法见 Wevu Router API。
位置与参数类型
RouterNavigation
类型签名:
interface RouterNavigation {
readonly nativeRouter: SetupContextRouter
readonly options: Readonly<UseRouterOptions>
readonly currentRoute: Readonly<RouteLocationNormalizedLoaded>
install: (app?: unknown) => void
resolve: (to: RouteLocationRaw) => RouteLocationNormalizedLoaded
isReady: () => Promise<void>
push: (to: RouteLocationRaw) => Promise<void | NavigationFailure>
replace: (to: RouteLocationRaw) => Promise<void | NavigationFailure>
back: (delta?: number) => Promise<void | NavigationFailure>
go: (delta: number) => Promise<void | NavigationFailure>
forward: () => Promise<void | NavigationFailure>
hasRoute: (name: string) => boolean
getRoutes: () => readonly RouteRecordRaw[]
addRoute: AddRoute
removeRoute: (name: string) => void
clearRoutes: () => void
beforeEach: (guard: NavigationGuard) => () => void
beforeResolve: (guard: NavigationGuard) => () => void
afterEach: (hook: NavigationAfterEach) => () => void
onError: (handler: NavigationErrorHandler) => () => void
}运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
createRouter() 返回的完整 Router 实例类型。
UseRouterOptions
类型签名:
interface UseRouterOptions {
tabBarEntries?: readonly (TypedRouterTabBarUrl | string)[]
/**
* Vue Router 对齐入口:推荐使用 `routes`
*/
routes?: readonly RouteRecordInput[]
/**
* 兼容入口:支持对象 map 或路由记录数组
*/
namedRoutes?: NamedRoutes
paramsMode?: RouteParamsMode
maxRedirects?: number
parseQuery?: RouteQueryParser
stringifyQuery?: RouteQueryStringifier
/**
* 异常型导航失败时是否以 Promise reject 抛出失败对象。
*
* - `true`:更贴近 Vue Router 心智(默认)
* - `false`:始终以返回值形式携带失败对象
*/
rejectOnError?: boolean
}运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
Router 创建选项,包含 routes、tabBar、params、query codec 和失败策略。
AddRoute
类型签名:
interface AddRoute {
(route: RouteRecordRaw): () => void
(parentName: string, route: RouteRecordRaw): () => void
}运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
router.addRoute() 的重载函数类型。
RouteLocationRaw
类型签名:
type RouteLocationRaw = string | {
path?: string
fullPath?: string
query?: LocationQueryRaw
hash?: string
name?: string
params?: RouteParamsRaw
}运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
导航方法接受的字符串或未规范化位置对象。
RouteLocationNormalizedLoaded
类型签名:
interface RouteLocationNormalizedLoaded {
path: string
fullPath: string
query: LocationQuery
hash: string
name?: string
meta?: RouteMeta
href?: string
matched?: readonly RouteRecordMatched[]
redirectedFrom?: RouteLocationRedirectedFrom
params: RouteParams
}运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
已解析并加载的当前路由位置。
RouteLocationRedirectedFrom
类型签名:
interface RouteLocationRedirectedFrom {
path: string
fullPath: string
query: LocationQuery
hash: string
name?: string
meta?: RouteMeta
href?: string
matched?: readonly RouteRecordMatched[]
params: RouteParams
}运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
重定向前原始位置的只读快照结构。
LocationQuery
类型签名:
type LocationQuery = Record<string, LocationQueryValue | LocationQueryValue[]>运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
规范化后的 query 对象。
LocationQueryRaw
类型签名:
type LocationQueryRaw = Record<string, LocationQueryValueRaw | LocationQueryValueRaw[]>运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
导航输入可接受的原始 query 对象。
LocationQueryValue
类型签名:
type LocationQueryValue = string | null运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
规范化 query 的单值类型。
LocationQueryValueRaw
类型签名:
type LocationQueryValueRaw = LocationQueryValue | number | boolean | undefined运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
原始 query 可接受的单值类型。
RouteParams
类型签名:
type RouteParams = Record<string, RouteParamValue | RouteParamValue[]>运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
规范化后的命名路由 params 对象。
RouteParamsRaw
类型签名:
type RouteParamsRaw = Record<string, RouteParamValueRaw | RouteParamValueRaw[]>运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
命名路由输入可接受的原始 params 对象。
RouteParamValue
类型签名:
type RouteParamValue = string运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
规范化 params 的字符串值类型。
RouteParamValueRaw
类型签名:
type RouteParamValueRaw = RouteParamValue | number | boolean | null | undefined运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
原始 params 可接受的单值类型。
RouteParamsMode
类型签名:
type RouteParamsMode = 'loose' | 'strict'运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
params 缺失或多余时采用的 loose 或 strict 策略。
RouteQueryParser
类型签名:
type RouteQueryParser = (search: string) => LocationQueryRaw | LocationQuery运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
自定义 query 解析函数签名。
RouteQueryStringifier
类型签名:
type RouteQueryStringifier = (query: LocationQueryRaw | LocationQuery) => string运行时说明: 该类型用于约束 位置与参数类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
自定义 query 序列化函数签名。
本组示例
用公开类型约束业务导航函数,避免手写字符串结构。
import type { RouteLocationRaw, RouteParamsRaw, UseRouterOptions } from 'wevu/router'
const params: RouteParamsRaw = { id: 42 }
const target: RouteLocationRaw = { name: 'detail', params }
const options: UseRouterOptions = {
routes: [{ name: 'detail', path: '/pages/detail/:id' }],
}守卫与失败类型
NavigationFailure
类型签名:
interface NavigationFailure extends Error {
readonly __wevuNavigationFailure: true
readonly type: NavigationFailureTypeValue
readonly to?: RouteLocationNormalizedLoaded
readonly from?: RouteLocationNormalizedLoaded
readonly cause?: unknown
}运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
带类型、目标、来源和 cause 的导航失败对象。
NavigationFailureTypeValue
类型签名:
type NavigationFailureTypeValue = (typeof NavigationFailureType)[keyof typeof NavigationFailureType]运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
NavigationFailureType 所有运行时值的联合类型。
NavigationMode
类型签名:
type NavigationMode = 'push' | 'replace' | 'back'运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
导航执行模式:push、replace 或 back。
NavigationRedirect
类型签名:
interface NavigationRedirect {
to: RouteLocationRaw
replace?: boolean
}运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
守卫或路由记录返回的重定向描述。
NavigationGuard
类型签名:
type NavigationGuard = (
to: RouteLocationNormalizedLoaded | undefined,
from: RouteLocationNormalizedLoaded,
context?: NavigationGuardContext,
) => NavigationGuardResult | Promise<NavigationGuardResult>运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
前置守卫函数签名。
NavigationGuardResult
类型签名:
type NavigationGuardResult = void | boolean | NavigationFailure | RouteLocationRaw | NavigationRedirect运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
守卫可返回的继续、取消、失败位置或重定向结果。
NavigationGuardContext
类型签名:
interface NavigationGuardContext {
readonly mode: NavigationMode
readonly to?: RouteLocationNormalizedLoaded
readonly from: RouteLocationNormalizedLoaded
readonly nativeRouter: SetupContextRouter
}运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
前置守卫获得的小程序导航上下文。
NavigationAfterEach
类型签名:
type NavigationAfterEach = (
to: RouteLocationNormalizedLoaded | undefined,
from: RouteLocationNormalizedLoaded,
failure?: NavigationFailure,
context?: NavigationAfterEachContext,
) => void | Promise<void>运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
导航完成回调签名。
NavigationAfterEachContext
类型签名:
interface NavigationAfterEachContext {
readonly mode: NavigationMode
readonly to?: RouteLocationNormalizedLoaded
readonly from: RouteLocationNormalizedLoaded
readonly nativeRouter: SetupContextRouter
readonly failure?: NavigationFailure
}运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
导航完成时的模式、位置、原生 Router 和失败信息。
NavigationErrorHandler
类型签名:
type NavigationErrorHandler = (
error: unknown,
context: NavigationErrorContext,
) => void | Promise<void>运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
异常型导航失败处理函数签名。
NavigationErrorContext
类型签名:
interface NavigationErrorContext {
readonly mode: NavigationMode
readonly to?: RouteLocationNormalizedLoaded
readonly from: RouteLocationNormalizedLoaded
readonly nativeRouter: SetupContextRouter
readonly failure: NavigationFailure
}运行时说明: 该类型用于约束 守卫与失败类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
错误处理器获得的导航上下文。
本组示例
守卫类型会同时约束目标、来源、上下文和返回值。
import type { NavigationAfterEach, NavigationGuard, NavigationGuardContext } from 'wevu/router'
const guard: NavigationGuard = (to, from, context?: NavigationGuardContext) => {
if (context?.mode === 'back') {
return true
}
return to?.meta?.disabled ? false : undefined
}
const afterEach: NavigationAfterEach = (to, from, failure) => {
console.log(to, from, failure)
}路由记录类型
NamedRouteRecord
类型签名:
interface NamedRouteRecord {
name: string
path: string
}运行时说明: 该类型用于约束 路由记录类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
最小命名路由记录,包含 name 和 path。
NamedRoutes
类型签名:
type NamedRoutes = Readonly<Record<string, string>> | readonly RouteRecordRaw[]运行时说明: 该类型用于约束 路由记录类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
命名路由对象 map 或路由记录数组。
RouteMeta
类型签名:
type RouteMeta = Record<string, unknown>运行时说明: 该类型用于约束 路由记录类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
路由记录自定义元信息。
RouteRecordInput
类型签名:
interface RouteRecordInput {
name?: string
path: string
meta?: RouteMeta
alias?: string | readonly string[]
children?: readonly RouteRecordInput[]
beforeEnter?: NavigationGuard | readonly NavigationGuard[]
redirect?: RouteRecordRedirect
}运行时说明: 该类型用于约束 路由记录类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
创建 Router 或添加动态路由时接受的记录结构。
RouteRecordRaw
类型签名:
interface RouteRecordRaw extends Omit<RouteRecordInput, 'name' | 'children'>, NamedRouteRecord {
children?: readonly RouteRecordRaw[]
}运行时说明: 该类型用于约束 路由记录类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
具有必填 name 的规范化公开路由记录。
RouteRecordMatched
类型签名:
interface RouteRecordMatched {
name: string
path: string
aliasPath?: string
meta?: RouteMeta
}运行时说明: 该类型用于约束 路由记录类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
当前路由 matched 中的匹配记录快照。
RouteRecordRedirect
类型签名:
type RouteRecordRedirect = RouteLocationRaw | NavigationRedirect | ((
to: RouteLocationNormalizedLoaded,
from: RouteLocationNormalizedLoaded,
) => RouteLocationRaw | NavigationRedirect | Promise<RouteLocationRaw | NavigationRedirect>)运行时说明: 该类型用于约束 路由记录类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
Vue Router 差异: 类型名称对齐 Vue Router 的常用概念,但字段只表达小程序路径、query、params、页面栈和原生 Router 能力,不包含浏览器 history/hash 状态。
示例: 见 本组示例。
路由记录的静态或函数式重定向类型。
本组示例
路由记录可以组合 meta、alias、children、守卫和重定向。
import type { RouteRecordInput } from 'wevu/router'
const routes: RouteRecordInput[] = [{
name: 'profile',
path: '/pages/profile/:id',
alias: '/profile/:id',
meta: { requiresLogin: true },
children: [{ name: 'profile-settings', path: 'settings' }],
}]小程序 Router 类型
SetupContextRouter
类型签名:
interface SetupContextRouter {
switchTab: (option: MiniProgramRouterSwitchTabOption) => ReturnType<MiniProgramRouter['switchTab']>
reLaunch: (option: MiniProgramRouterReLaunchOption) => ReturnType<MiniProgramRouter['reLaunch']>
redirectTo: (option: MiniProgramRouterRedirectToOption) => ReturnType<MiniProgramRouter['redirectTo']>
navigateTo: (option: MiniProgramRouterNavigateToOption) => ReturnType<MiniProgramRouter['navigateTo']>
navigateBack: MiniProgramRouter['navigateBack']
}运行时说明: 该类型用于约束 小程序 Router 类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
示例: 见 本组示例。
Wevu setup() 上下文提供的原生小程序 Router。
RouterNavigateToOption
类型签名:
type RouterNavigateToOption = MiniProgramRouterNavigateToOption运行时说明: 该类型用于约束 小程序 Router 类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
示例: 见 本组示例。
类型安全的 navigateTo 选项。
RouterRedirectToOption
类型签名:
type RouterRedirectToOption = MiniProgramRouterRedirectToOption运行时说明: 该类型用于约束 小程序 Router 类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
示例: 见 本组示例。
类型安全的 redirectTo 选项。
RouterReLaunchOption
类型签名:
type RouterReLaunchOption = MiniProgramRouterReLaunchOption运行时说明: 该类型用于约束 小程序 Router 类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
示例: 见 本组示例。
类型安全的 reLaunch 选项。
RouterSwitchTabOption
类型签名:
type RouterSwitchTabOption = MiniProgramRouterSwitchTabOption运行时说明: 该类型用于约束 小程序 Router 类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
示例: 见 本组示例。
类型安全的 switchTab 选项。
TypedRouterUrl
类型签名:
type TypedRouterUrl = RouterUrl<ResolveTypedRouterEntries>运行时说明: 该类型用于约束 小程序 Router 类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
示例: 见 本组示例。
由项目路由类型映射推导出的页面 URL。
TypedRouterTabBarUrl
类型签名:
type TypedRouterTabBarUrl = RouterPathUrl<ResolveTypedRouterTabBarEntries>运行时说明: 该类型用于约束 小程序 Router 类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
示例: 见 本组示例。
由项目路由类型映射推导出的 tabBar URL。
WevuTypedRouterRouteMap
类型签名:
interface WevuTypedRouterRouteMap {}运行时说明: 该类型用于约束 小程序 Router 类型 的公开契约,不会在运行时产生额外对象;应从 wevu/router 以 import type 导入。
示例: 见 本组示例。
供项目声明合并扩展的类型路由映射。
本组示例
项目可以通过声明合并收窄原生 Router 接受的 URL。
import type { TypedRouterUrl, WevuTypedRouterRouteMap } from 'wevu/router'
declare module 'wevu/router' {
interface WevuTypedRouterRouteMap {
entries: '/pages/home/index' | '/pages/detail/index'
tabBarEntries: '/pages/home/index'
}
}
const url: TypedRouterUrl<WevuTypedRouterRouteMap> = '/pages/detail/index'