@xsyx/easy-route
Advanced tools
Comparing version 1.0.2 to 1.0.3
let beforeRoute | ||
let afterRoute | ||
// 对象深拷贝 | ||
function deepCopy(target) { | ||
let copyed_objs = []; //此数组解决了循环引用和相同引用的问题,它存放已经递归到的目标对象 | ||
function _deepCopy(target) { | ||
if ((typeof target !== 'object') || !target) { | ||
return target; | ||
} | ||
for (let i = 0; i < copyed_objs.length; i++) { | ||
if (copyed_objs[i].target === target) { | ||
return copyed_objs[i].copyTarget; | ||
} | ||
} | ||
let obj = {}; | ||
if (Array.isArray(target)) { | ||
obj = []; //处理target是数组的情况 | ||
} | ||
copyed_objs.push({ | ||
target: target, | ||
copyTarget: obj | ||
}) | ||
Object.keys(target).forEach(key => { | ||
if (obj[key]) { | ||
return; | ||
} | ||
obj[key] = _deepCopy(target[key]); | ||
}); | ||
return obj; | ||
} | ||
return _deepCopy(target); | ||
} | ||
//获取路由信息,来源from 目标to | ||
function _getRouteInfo(targetRoutePath) { | ||
let app = getApp() | ||
let router = app.globalData.router | ||
let router = deepCopy(app.globalData.router) | ||
if (targetRoutePath.substr(0, 1) !== '/') { | ||
@@ -13,3 +45,3 @@ targetRoutePath = '/' + targetRoutePath | ||
}) | ||
to = to[0] | ||
to = to[0] || {} | ||
let allPages = getCurrentPages() | ||
@@ -24,3 +56,3 @@ let currentPage = allPages[allPages.length - 1] | ||
}) | ||
from = from[0] | ||
from = from[0] || {} | ||
return { | ||
@@ -51,3 +83,4 @@ from, | ||
}, | ||
fail: () => { | ||
fail: (e) => { | ||
console.log(e) | ||
option.fail && option.fail() | ||
@@ -77,3 +110,3 @@ }, | ||
* @param {String} option.path 页面路径,保持和router路由配置中一致,必传参数 | ||
* @param {Object} option.params 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的params | ||
* @param {query} option.query 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的query | ||
* @param {Object} option.meta 自定义数据,和router-config.js中的meta合并数据,并覆盖相同配置 | ||
@@ -92,5 +125,5 @@ * @param {Function} option.success 跳转成功回调 | ||
} = routeInfo | ||
option.params && (to.params = option.params) | ||
option.query && (to.query = option.query) | ||
option.meta && Object.assign(to.meta, option.meta) | ||
let url = to.path + _formatUrl(to.params) | ||
let url = to.path + _formatUrl(to.query) | ||
let next = function (canJump = true) { | ||
@@ -117,2 +150,3 @@ if (!canJump) return | ||
function navigateBack(option) { | ||
option = option || {} | ||
let delta = option.delta || 1 | ||
@@ -147,3 +181,3 @@ let allPages = getCurrentPages() | ||
* @param {String} option.path 页面路径,保持和router路由配置中一致,必传参数 | ||
* @param {Object} option.params 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的params | ||
* @param {Object} option.query 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的query | ||
* @param {Object} option.meta 自定义数据,和router-config.js中的meta合并数据,并覆盖相同配置 | ||
@@ -162,5 +196,5 @@ * @param {Function} option.success 跳转成功回调 | ||
} = routeInfo | ||
option.params && (to.params = option.params) | ||
option.query && (to.query = option.query) | ||
option.meta && Object.assign(to.meta, option.meta) | ||
let url = to.path + _formatUrl(to.params) | ||
let url = to.path + _formatUrl(to.query) | ||
let next = function (canJump = true) { | ||
@@ -181,3 +215,3 @@ if (!canJump) return | ||
* @param {String} option.path 页面路径,保持和router路由配置中一致,必传参数 | ||
* @param {Object} option.params 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的params | ||
* @param {Object} option.query 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的query | ||
* @param {Object} option.meta 自定义数据,和router-config.js中的meta合并数据,并覆盖相同配置 | ||
@@ -195,5 +229,5 @@ * @param {Function} option.success 跳转成功回调 | ||
} = routeInfo | ||
option.params && (to.params = option.params) | ||
option.query && (to.query = option.query) | ||
option.meta && Object.assign(to.meta, option.meta) | ||
let url = to.path + _formatUrl(to.params) | ||
let url = to.path + _formatUrl(to.query) | ||
let next = function (canJump = true) { | ||
@@ -200,0 +234,0 @@ if (!canJump) return |
{ | ||
"name": "@xsyx/easy-route", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "wx-mp-route", | ||
@@ -5,0 +5,0 @@ "mode": "util", |
let beforeRoute | ||
let afterRoute | ||
// 对象深拷贝 | ||
function deepCopy(target) { | ||
let copyed_objs = []; //此数组解决了循环引用和相同引用的问题,它存放已经递归到的目标对象 | ||
function _deepCopy(target) { | ||
if ((typeof target !== 'object') || !target) { | ||
return target; | ||
} | ||
for (let i = 0; i < copyed_objs.length; i++) { | ||
if (copyed_objs[i].target === target) { | ||
return copyed_objs[i].copyTarget; | ||
} | ||
} | ||
let obj = {}; | ||
if (Array.isArray(target)) { | ||
obj = []; //处理target是数组的情况 | ||
} | ||
copyed_objs.push({ | ||
target: target, | ||
copyTarget: obj | ||
}) | ||
Object.keys(target).forEach(key => { | ||
if (obj[key]) { | ||
return; | ||
} | ||
obj[key] = _deepCopy(target[key]); | ||
}); | ||
return obj; | ||
} | ||
return _deepCopy(target); | ||
} | ||
//获取路由信息,来源from 目标to | ||
function _getRouteInfo(targetRoutePath) { | ||
let app = getApp() | ||
let router = app.globalData.router | ||
if(targetRoutePath.substr(0,1) !== '/'){ | ||
targetRoutePath = '/' + targetRoutePath | ||
let router = deepCopy(app.globalData.router) | ||
if (targetRoutePath.substr(0, 1) !== '/') { | ||
targetRoutePath = '/' + targetRoutePath | ||
} | ||
@@ -13,8 +45,8 @@ let to = router.filter((item) => { | ||
}) | ||
to = to[0] | ||
to = to[0] || {} | ||
let allPages = getCurrentPages() | ||
let currentPage = allPages[allPages.length - 1] | ||
let currentPath = currentPage.route | ||
if(currentPath.substr(0,1) !== '/'){ | ||
currentPath = '/' + currentPath | ||
if (currentPath.substr(0, 1) !== '/') { | ||
currentPath = '/' + currentPath | ||
} | ||
@@ -24,3 +56,3 @@ let from = router.filter((item) => { | ||
}) | ||
from = from[0] | ||
from = from[0] || {} | ||
return { | ||
@@ -51,3 +83,4 @@ from, | ||
}, | ||
fail: () => { | ||
fail: (e) => { | ||
console.log(e) | ||
option.fail && option.fail() | ||
@@ -77,3 +110,3 @@ }, | ||
* @param {String} option.path 页面路径,保持和router路由配置中一致,必传参数 | ||
* @param {Object} option.params 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的params | ||
* @param {query} option.query 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的query | ||
* @param {Object} option.meta 自定义数据,和router-config.js中的meta合并数据,并覆盖相同配置 | ||
@@ -92,5 +125,5 @@ * @param {Function} option.success 跳转成功回调 | ||
} = routeInfo | ||
option.params && (to.params = option.params) | ||
option.query && (to.query = option.query) | ||
option.meta && Object.assign(to.meta, option.meta) | ||
let url = to.path + _formatUrl(to.params) | ||
let url = to.path + _formatUrl(to.query) | ||
let next = function (canJump = true) { | ||
@@ -117,2 +150,3 @@ if (!canJump) return | ||
function navigateBack(option) { | ||
option = option || {} | ||
let delta = option.delta || 1 | ||
@@ -147,3 +181,3 @@ let allPages = getCurrentPages() | ||
* @param {String} option.path 页面路径,保持和router路由配置中一致,必传参数 | ||
* @param {Object} option.params 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的params | ||
* @param {Object} option.query 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的query | ||
* @param {Object} option.meta 自定义数据,和router-config.js中的meta合并数据,并覆盖相同配置 | ||
@@ -162,5 +196,5 @@ * @param {Function} option.success 跳转成功回调 | ||
} = routeInfo | ||
option.params && (to.params = option.params) | ||
option.query && (to.query = option.query) | ||
option.meta && Object.assign(to.meta, option.meta) | ||
let url = to.path + _formatUrl(to.params) | ||
let url = to.path + _formatUrl(to.query) | ||
let next = function (canJump = true) { | ||
@@ -181,3 +215,3 @@ if (!canJump) return | ||
* @param {String} option.path 页面路径,保持和router路由配置中一致,必传参数 | ||
* @param {Object} option.params 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的params | ||
* @param {Object} option.query 页面URL参数 {a:11,b:22} 格式化成?a=11&b=22,覆盖在router-config.js中的query | ||
* @param {Object} option.meta 自定义数据,和router-config.js中的meta合并数据,并覆盖相同配置 | ||
@@ -195,5 +229,5 @@ * @param {Function} option.success 跳转成功回调 | ||
} = routeInfo | ||
option.params && (to.params = option.params) | ||
option.query && (to.query = option.query) | ||
option.meta && Object.assign(to.meta, option.meta) | ||
let url = to.path + _formatUrl(to.params) | ||
let url = to.path + _formatUrl(to.query) | ||
let next = function (canJump = true) { | ||
@@ -200,0 +234,0 @@ if (!canJump) return |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23637
542