前言

    mpvue-router-patch是mpvue 中使用 vue-router兼容的路由

使用

// 在src/main.js

import Vue from 'vue'
import MpvueRouterPatch from 'mpvue-router-patch'
Vue.use(MpvueRouterPatch)

方法

  • $router.push(location, onComplete?, onAbort?, onSuccess?)

        跳转到应用内的某个页面,mpvue.navigateTompvue.switchTabmpvue.reLaunch均通过该方法实现,location 参数支持字符串及对象两种形式,跳转至 tabBar 页面或重启至某页面时必须以对象形式传入

// 字符串
this.$router.push('/pages/news/detail')
// 对象
this.$router.push({ path: '/pages/news/detail' })
// 带查询参数,变成 /pages/news/detail?id=1
this.$router.push({ path: '/pages/news/detail', query: { id: 1 } })
// 切换至 tabBar 页面
this.$router.push({ path: '/pages/news/list', isTab: true })
// 重启至某页面,无需指定是否为 tabBar 页面,但 tabBar 页面无法携带参数
this.$router.push({ path: '/pages/news/list', reLaunch: true })

    注意: 返回tab页面需要加上 isTab: true

  • this.$router.go(n)

    关闭当前页面,返回上一页面或多级页面,n 为回退层数,默认值为 1

  • this.$router.back()

    关闭当前页面,返回上一页面

详情见:https://www.npmjs.com/package/mpvue-router-patch

Logo

前往低代码交流专区

更多推荐