uniapp app端路由管理封裝

當(dāng)前封裝并沒有加動態(tài)路由 如有需要可手動添加一個 盛路由的數(shù)組 在跳轉(zhuǎn)前進行判斷

全局注冊
import Router from '@/common/utils/router';
export default {
  install: function (Vue) {
    Vue.prototype.router = new Router();
  }
}

路由封裝

/**
 * @exports
 * 全局路由管理
 */
export default class Router {
  constructor() {
    console.log("global router class");
  }
  success () {
    console.log("跳轉(zhuǎn)成功");
  }
  fail (err) {
    console.error("跳轉(zhuǎn)失?。?, err);
  }
  /**
   * 保留當(dāng)前頁面,跳轉(zhuǎn)到應(yīng)用內(nèi)的某個頁面。
   * @param { String } url 目標(biāo)地址
   * @description 使用uni.navigateBack可以返回到原頁面
   * @example this.$router.push(url); => 去往指定頁面
   */
  push (url) {
    uni.navigateTo({
      url,
      success: this.success,
      fail: this.fail
    });
  }
  /**
   * 關(guān)閉當(dāng)前頁面,返回上一頁面或多級頁面。
   * @param { num } delta 返回層級
   * @description 可通過 getCurrentPages() 獲取當(dāng)前的頁面棧,決定需要返回幾層。
   * @example this.$router.back() => 返回上一頁面
   */
  back (delta = 1) {
    uni.navigateBack({
      delta
    });
  }
  /**
   * 跳轉(zhuǎn)到 tabBar 頁面,并關(guān)閉其他所有非 tabBar 頁面。
   * @param { String } url 目標(biāo)地址
   * @example this.$router.goGlobal(url) => 返回上一頁面
   */
  goGlobal (url) {
    uni.switchTab({
      url,
      success: this.success,
      fail: this.fail
    })
  }
  /**
   * 關(guān)閉所有頁面,打開到應(yīng)用內(nèi)的某個頁面。
   * @param { String } url 目標(biāo)地址
   * @example this.$router.redirect(url) => 重定向到目標(biāo)頁面
   */
  redirect (url) {
    uni.reLaunch({
      url
    });
  }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容