路由跳转

route(Object)此为一个路由跳转方法,内部是对uni多个路由跳转api的封装,更方便使用

Object参数说明:

参数类型默认值是否必填说明
typeStringnavigateTofalsenavigateToto对应uni.navigateToredirectredirectTo对应uni.redirectToswitchTabtab对应uni.switchTabreLaunch对应uni.reLaunchnavigateBackback对应uni.navigateBack
urlString-falsetypenavigateToredirectToswitchTabreLaunch时为必填
deltaNumber1falsetypenavigateBack时用到,表示返回的页面数
paramsObject-false传递的对象形式的参数,如{name: 'lisa', age: 18}
animationTypeStringpop-infalse只在APP生效,详见窗口动画open in new window
animationDurationNumber300false动画持续时间,单位ms
interceptBooleanfalsefalse是否需要拦截

基本使用

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')