@maskedeng-tom/ssrsx
Version:
server side renderer with tsx
29 lines • 1.13 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHref = exports.useHref = void 0;
const path_1 = __importDefault(require("path"));
const useLocation_1 = require("../hooks/useLocation");
////////////////////////////////////////////////////////////////////////////////
const addHref = (pathname, href) => {
let targetFullUrl = href;
if ((href.slice(0, 1) !== '/')) {
if (pathname.slice(-1) === '/') {
targetFullUrl = `${pathname}${href}`;
}
else {
targetFullUrl = `${pathname.split('/').slice(0, -1).join('/')}/${href}`;
}
}
return path_1.default.normalize(targetFullUrl);
};
////////////////////////////////////////////////////////////////////////////////
const useHref = (href) => {
const location = (0, useLocation_1.useLocation)();
return addHref(location.pathname, href);
};
exports.useHref = useHref;
exports.getHref = useHref;
//# sourceMappingURL=useHref.js.map