@foxpage/foxpage-node-sdk
Version:
foxpage node sdk
27 lines (26 loc) • 784 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPathname = void 0;
/**
* get pathname
* @param ctx
* @returns
*/
const getPathname = (slug, ctx) => {
const { path = '', rewrite } = ctx.matchedRoute || {};
const { pathname = '' } = ctx.URL || {};
// rewrite by app customize
if (rewrite) {
let rewritePath = '';
if (typeof rewrite === 'string') {
rewritePath = rewrite;
}
else if (typeof rewrite === 'function') {
rewritePath = rewrite(pathname) || '';
}
return rewritePath;
}
const replaceRoute = path || (slug ? `/${slug}/` : '');
return replaceRoute ? pathname.replace(replaceRoute, '/') : pathname;
};
exports.getPathname = getPathname;