# vue-router-extention **Repository Path**: hainee/vue-router-extention ## Basic Information - **Project Name**: vue-router-extention - **Description**: 对VueRouter进行了一些有意思的扩展,配合vue-router-module很好用的哦! - **Primary Language**: JavaScript - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-06-18 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 一个VueRouter的插件 ## 安装 npm i vue-router-extensions ## 使用 import RouterExtention from 'vue-router-extention' import router from 'your roter's definition' RouterExtention.init(router) 扩展了一些有用的方法: 1. function router.show(param, onreturn, callback, thisObj, replace) 显示指定路由并传递参数对象,可指定路由返回时的回调函数和子路由回调函数 @param {Object} param Vue路由的原始参数 @param {Function} onreturn 当路由返回是的回调函数 @param {Object} thisObj 回调函数中的this对象 @param {Function} callback 可在子路由直接调用的回调函数 @param {Boolean} replace 是否replace当前路由 例子: this.$router.show({ name: 'projectList.detailView', params: {id:100} },res=>{ // 路由返回的回调 }, res=>{ // 子路由回调 }) 2. function router.showChild(param, onreturn, callback, thisObj) 显示当前路由下指定名称的子路由,可指定路由返回时的回调函数和子路由回调函数 @param {Object} param Vue路由的原始参数 @param {Function} onreturn 当路由返回是的回调函数 @param {Function} callback 可在子路由直接调用的回调函数 @param {Object} thisObj 回调函数中的this对象 例子: this.$router.showChild({ name: 'detailView', params: {id:100} },res=>{ // 路由返回的回调 }, res=>{ // 子路由回调 }) 3. function router.replaceChild(param, onreturn, callback, thisObj) 以replace模式显示当前路由下指定名称的子路由,可指定路由返回时的回调函数和子路由回调函数 @param {Object} param Vue路由的原始参数 @param {Function} onreturn 当路由返回是的回调函数 @param {Function} callback 可在子路由直接调用的回调函数 @param {Object} thisObj 回调函数中的this对象 例子: this.$router.replaceChild({ name: 'detailView', params: {id:100} },res=>{ // 路由返回的回调 }, res=>{ // 子路由回调 }) 4. async function router.return(param) 异步函数,返回到上一步路由同时可传递参数 @param {Object} param 返回的参数 例子: this.$router.return({ name: 'hainee', age: 39 }) 5. async function router.returnTo(param) 异步函数,返回到指定name的路由并返回参数 @param {Object} param 返回的参数 {name: 'returnToRouteName'} 例子: await this.$router.returnTo('projectList') await this.$router.returnTo({ name: 'projectList', param: {} }) 6. function router.backTo(name) 返回到指定name的路由 例子: this.$router.backTo('projectList') 7. function router.callback(param) 调用当前子路由的回调函数 @param {Object} param 参数 例子: this.$router.callback({...}) ## 特殊说明 该组件最好配合vue-router-module组件使用