router
若您有跨端需求,您可以使用 router 对象实现您的路由跳转。
router.push(url: string)
router.replace(url: string) // 参数获取同push
router.back()
router.go(delta: number)
router.reload()
引入
import { router } from '@ray-js/ray';
使用
/// routers.config.ts
import { Routes } from '@ray-js/types';
export const routes: Routes = [
{
route: '/',
path: '/pages/home/index',
},
{
route: '/detail/:uid',
path: '/pages/detail/index',
},
{
route: '/my',
path: '/pages/my/index',
},
];
push
router.push(url: string)
hash 参数
router.push('/detail/1234')
detail 页面的路由配置为 /detail/:uid
,您可以在 detail
页面的 props.location.query.uid
获取 uid
。
query 参数
router.push('/detail/1234?name=tuya')
您可以在 detail
页面的 props.location.query.name
获取 query
参数 name
。
👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。
navigateBack
关闭当前页面,返回上一页面或多级页面
引入
import { navigateBack } from '@ray-js/ray';
需引入
MiniKit
,且在>=2.0.0
版本才可使用
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
delta | number | 否 | 返回的页面数,如果 delta 大于现有页面数,则返回到首页 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
navigateTo
路由到新页面
引入
import { navigateTo } from '@ray-js/ray';
需引入
MiniKit
,且在>=2.0.0
版本才可使用
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
url | string | 是 | 页面路径 | |
type | string | 否 | 打开方式,支持全屏 full,半屏 half;默认全屏 full | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
redirectTo
关闭当前页面,跳转到应用内的某个页面
引入
import { redirectTo } from '@ray-js/ray';
需引入
MiniKit
,且在>=2.0.0
版本才可使用
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
url | string | 是 | 页面路径 | |
type | string | 否 | 打开方式,支持全屏 full,半屏 half;默认全屏 full | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
reLaunch
关闭所有页面,打开到应用内的某个页面
引入
import { reLaunch } from '@ray-js/ray';
需引入
MiniKit
,且在>=2.0.0
版本才可使用
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
url | string | 是 | 页面路径 | |
type | string | 否 | 打开方式,支持全屏 full,半屏 half;默认全屏 full | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
switchTab
跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
引入
import { switchTab } from '@ray-js/ray';
需引入
MiniKit
,且在>=2.0.0
版本才可使用
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
url | string | 是 | 页面路径 | |
type | string | 否 | 打开方式,支持全屏 full,半屏 half;默认全屏 full | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。