t-comm
Version:
专业、稳定、纯粹的工具库
46 lines (39 loc) • 1.26 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var _typeof = require('@babel/runtime/helpers/typeof');
var tslib_es6 = require('../tslib.es6-0d92ef81.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
/**
* 根据路由跳转时的参数,提取 path 和其他参数
* @param route $router.push 或者 $router.replace 的参数
* @returns 解析结果
* @example
* ```ts
* getRouterFuncPath('/foo/bar');
* // { path: '/foo/bar', other: {} }
*
* getRouterFuncPath({ path: '/foo/bar', query: { a: 1 } });
* // { path: '/foo/bar', other: { query: { a: 1 } } }
*
* getRouterFuncPath({ name: 'home' });
* // { path: undefined, other: {} }
* ```
*/
function getRouterFuncPath(route) {
var rawPath;
var rawOther = {};
if (_typeof__default["default"](route) === 'object' && route.path) {
rawPath = route.path;
route.path;
var other = tslib_es6.__rest(route, ["path"]);
rawOther = other;
} else if (typeof route === 'string') {
rawPath = route;
}
return {
path: rawPath,
other: rawOther
};
}
exports.getRouterFuncPath = getRouterFuncPath;