htmx-router 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/components.js +1 -1
- package/bin/router.js +5 -3
- package/bin/shared.d.ts +1 -1
- package/package.json +1 -1
package/bin/components.js
CHANGED
|
@@ -26,6 +26,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.Link = void 0;
|
|
27
27
|
const elements = __importStar(require("typed-html"));
|
|
28
28
|
function Link(props, contents) {
|
|
29
|
-
return elements.createElement("a", { target: props.target || "", style: props.style || "", href: props.to, "hx-get": props.to
|
|
29
|
+
return elements.createElement("a", { target: props.target || "", style: props.style || "", href: props.to, "hx-get": props.to }, contents);
|
|
30
30
|
}
|
|
31
31
|
exports.Link = Link;
|
package/bin/router.js
CHANGED
|
@@ -51,8 +51,10 @@ class RouteLeaf {
|
|
|
51
51
|
}
|
|
52
52
|
async render(args, mask, routeName) {
|
|
53
53
|
try {
|
|
54
|
+
// Always check auth
|
|
55
|
+
// If auth error this function will throw
|
|
54
56
|
if (this.module.Auth)
|
|
55
|
-
|
|
57
|
+
await this.module.Auth(args);
|
|
56
58
|
if (mask === render_args_1.MaskType.show) {
|
|
57
59
|
if (this.module.Render)
|
|
58
60
|
return await this.module.Render(routeName, args);
|
|
@@ -161,13 +163,13 @@ class RouteTree {
|
|
|
161
163
|
return new shared_1.Redirect(url.pathname.slice(0, -1) + url.search);
|
|
162
164
|
}
|
|
163
165
|
const args = new render_args_1.RenderArgs(req, res, url);
|
|
164
|
-
|
|
166
|
+
res.setHeader('Vary', "hx-current-url");
|
|
167
|
+
const from = req.headers['hx-current-url'] ?
|
|
165
168
|
new URL(((_a = req.headers['hx-current-url']) === null || _a === void 0 ? void 0 : _a.toString()) || "/").pathname :
|
|
166
169
|
"";
|
|
167
170
|
try {
|
|
168
171
|
const depth = BuildOutlet(this, args, from);
|
|
169
172
|
if (from) {
|
|
170
|
-
res.setHeader('Vary', "HX-Push-Url");
|
|
171
173
|
res.setHeader('HX-Push-Url', req.url || "/");
|
|
172
174
|
if (depth > 0) {
|
|
173
175
|
res.setHeader('HX-Retarget', `#hx-route-${depth.toString(16)}`);
|
package/bin/shared.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { RenderArgs } from "./render-args";
|
|
|
5
5
|
export type Outlet = () => Promise<string>;
|
|
6
6
|
export type CatchFunction = (routeName: string, args: RenderArgs, err: ErrorResponse) => Promise<string>;
|
|
7
7
|
export type RenderFunction = (routeName: string, args: RenderArgs) => Promise<string>;
|
|
8
|
-
export type AuthFunction = (args: RenderArgs) => Promise<
|
|
8
|
+
export type AuthFunction = (args: RenderArgs) => Promise<void>;
|
|
9
9
|
export type RouteModule = {
|
|
10
10
|
Render?: RenderFunction;
|
|
11
11
|
CatchError?: CatchFunction;
|