路由跳转
route(Object)此为一个路由跳转方法,内部是对uni多个路由跳转api的封装,更方便使用
Object参数说明:
参数 | 类型 | 默认值 | 是否必填 | 说明 |
---|---|---|---|---|
type | String | navigateTo | false | navigateTo 或to 对应uni.navigateTo ,redirect 或redirectTo 对应uni.redirectTo ,switchTab 或tab 对应uni.switchTab ,reLaunch 对应uni.reLaunch ,navigateBack 或back 对应uni.navigateBack |
url | String | - | false | type 为navigateTo ,redirectTo ,switchTab ,reLaunch 时为必填 |
delta | Number | 1 | false | type 为navigateBack 时用到,表示返回的页面数 |
params | Object | - | false | 传递的对象形式的参数,如{name: 'lisa', age: 18} |
animationType | String | pop-in | false | 只在APP生效,详见窗口动画 |
animationDuration | Number | 300 | false | 动画持续时间,单位ms |
intercept | Boolean | false | false | 是否需要拦截 |
基本使用
uni.$m.route({
url: 'pages/index/index',
params: {
name: 'test'
}
})
简写
// 无参数
uni.$m.route('/pages/index/index')
// 带参数
uni.$m.route('/pages/index/index', {
name: 'test'
})
拦截
uni.$routeIntercept = (config = {}, next) => {
if (config.url === '/pages/login/login') {
next(true)
} else {
next(false)
}
}
uni.$m.route('/pages/index/index')
uni.$m.route('/pages/login/login')