@real-router/solid 0.2.0 → 0.2.2
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/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +13 -8
- package/dist/esm/index.d.mts +3 -3
- package/dist/esm/index.mjs +13 -8
- package/dist/types/context.d.ts +1 -1
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/directives/link.d.ts.map +1 -1
- package/dist/types/types.d.ts +2 -2
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/directives/link.tsx +9 -2
- package/src/types.ts +2 -5
package/dist/cjs/index.d.ts
CHANGED
|
@@ -39,8 +39,8 @@ declare const RouteView: typeof RouteViewRoot & {
|
|
|
39
39
|
NotFound: typeof NotFound;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
interface RouteState<P extends Params = Params
|
|
43
|
-
route: State<P
|
|
42
|
+
interface RouteState<P extends Params = Params> {
|
|
43
|
+
route: State<P> | undefined;
|
|
44
44
|
previousRoute?: State | undefined;
|
|
45
45
|
}
|
|
46
46
|
interface LinkProps<P extends Params = Params> extends Omit<JSX.HTMLAttributes<HTMLAnchorElement>, "onClick"> {
|
|
@@ -101,7 +101,7 @@ interface RouterContextValue {
|
|
|
101
101
|
routeSelector: (routeName: string) => boolean;
|
|
102
102
|
}
|
|
103
103
|
declare const RouterContext: solid_js.Context<RouterContextValue | null>;
|
|
104
|
-
declare const RouteContext: solid_js.Context<Accessor<RouteState<_real_router_core.Params
|
|
104
|
+
declare const RouteContext: solid_js.Context<Accessor<RouteState<_real_router_core.Params>> | null>;
|
|
105
105
|
|
|
106
106
|
declare function createSignalFromSource<T>(source: RouterSource<T>): Accessor<T>;
|
|
107
107
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -148,7 +148,7 @@ const RouteView = Object.assign(RouteViewRoot, {
|
|
|
148
148
|
NotFound
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
const e=`data-real-router-announcer`;function t(e,t){let o=`Navigated to `,c=true,l=false,u=false,d=``,f,p=n(),m=setTimeout(()=>{l=true;},100),h=e.subscribe(({route:e})=>{if(c){c=false;return}requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(u)return;let t=i(e,o);t&&t!==d&&l&&(d=t,clearTimeout(f),p.textContent=t,f=setTimeout(()=>{p.textContent=``,d=``;},7e3),a());});});});return {destroy(){u=true,h(),clearTimeout(f),clearTimeout(m),r();}}}function n(){let t=document.querySelector(`[${e}]`);if(t)return t;let n=document.createElement(`div`);return n.setAttribute(`style`,`position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);clip-path:inset(50%);white-space:nowrap;border:0`),n.setAttribute(`aria-live`,`assertive`),n.setAttribute(`aria-atomic`,`true`),n.setAttribute(e,``),document.body.prepend(n),n}function r(){document.querySelector(`[${e}]`)?.remove();}function i(e,t,n){let r=document.querySelector(`h1`)?.textContent.trim()??``,i=e.name.startsWith(`@@`)?``:e.name;return `${t}${r||document.title||i||globalThis.location.pathname}`}function a(){let e=document.querySelector(`h1`);e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:true}));}function o(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function s(e,t,n){try{let r=e.buildUrl;return r?r(t,n):e.buildPath(t,n)}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function c(e,t,n){return e&&t?n?`${n} ${t}`.trim():t:n??void 0}function l(e){e instanceof HTMLAnchorElement||e instanceof HTMLButtonElement||(e.getAttribute(`role`)||e.setAttribute(`role`,`link`),e.getAttribute(`tabindex`)||e.setAttribute(`tabindex`,`0`));}
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
154
|
* Stable empty object for default params
|
|
@@ -177,7 +177,7 @@ function Link(props) {
|
|
|
177
177
|
strict: local.activeStrict,
|
|
178
178
|
ignoreQueryParams: local.ignoreQueryParams
|
|
179
179
|
}));
|
|
180
|
-
const href = solidJs.createMemo(() =>
|
|
180
|
+
const href = solidJs.createMemo(() => s(router, local.routeName, local.routeParams));
|
|
181
181
|
const handleClick = evt => {
|
|
182
182
|
if (local.onClick) {
|
|
183
183
|
local.onClick(evt);
|
|
@@ -185,13 +185,13 @@ function Link(props) {
|
|
|
185
185
|
return;
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
if (!
|
|
188
|
+
if (!o(evt) || local.target === "_blank") {
|
|
189
189
|
return;
|
|
190
190
|
}
|
|
191
191
|
evt.preventDefault();
|
|
192
192
|
router.navigate(local.routeName, local.routeParams, local.routeOptions).catch(() => {});
|
|
193
193
|
};
|
|
194
|
-
const finalClassName = solidJs.createMemo(() =>
|
|
194
|
+
const finalClassName = solidJs.createMemo(() => c(isActive(), local.activeClassName, local.class));
|
|
195
195
|
return (() => {
|
|
196
196
|
var _el$ = _tmpl$();
|
|
197
197
|
web.spread(_el$, web.mergeProps(rest, {
|
|
@@ -245,9 +245,14 @@ function link(element, accessor) {
|
|
|
245
245
|
|
|
246
246
|
// Set href on <a> elements
|
|
247
247
|
if (element instanceof HTMLAnchorElement) {
|
|
248
|
-
|
|
248
|
+
const href = s(router, options.routeName, options.routeParams ?? EMPTY_PARAMS);
|
|
249
|
+
if (href === undefined) {
|
|
250
|
+
element.removeAttribute("href");
|
|
251
|
+
} else {
|
|
252
|
+
element.href = href;
|
|
253
|
+
}
|
|
249
254
|
}
|
|
250
|
-
|
|
255
|
+
l(element);
|
|
251
256
|
|
|
252
257
|
// Active class tracking (reactive)
|
|
253
258
|
if (options.activeClassName) {
|
|
@@ -264,7 +269,7 @@ function link(element, accessor) {
|
|
|
264
269
|
|
|
265
270
|
// Click handler
|
|
266
271
|
function handleClick(evt) {
|
|
267
|
-
if (!
|
|
272
|
+
if (!o(evt)) {
|
|
268
273
|
return;
|
|
269
274
|
}
|
|
270
275
|
if (element instanceof HTMLAnchorElement) {
|
|
@@ -336,7 +341,7 @@ function RouterProvider(props) {
|
|
|
336
341
|
if (!props.announceNavigation) {
|
|
337
342
|
return;
|
|
338
343
|
}
|
|
339
|
-
const announcer =
|
|
344
|
+
const announcer = t(props.router);
|
|
340
345
|
solidJs.onCleanup(() => {
|
|
341
346
|
announcer.destroy();
|
|
342
347
|
});
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -39,8 +39,8 @@ declare const RouteView: typeof RouteViewRoot & {
|
|
|
39
39
|
NotFound: typeof NotFound;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
interface RouteState<P extends Params = Params
|
|
43
|
-
route: State<P
|
|
42
|
+
interface RouteState<P extends Params = Params> {
|
|
43
|
+
route: State<P> | undefined;
|
|
44
44
|
previousRoute?: State | undefined;
|
|
45
45
|
}
|
|
46
46
|
interface LinkProps<P extends Params = Params> extends Omit<JSX.HTMLAttributes<HTMLAnchorElement>, "onClick"> {
|
|
@@ -101,7 +101,7 @@ interface RouterContextValue {
|
|
|
101
101
|
routeSelector: (routeName: string) => boolean;
|
|
102
102
|
}
|
|
103
103
|
declare const RouterContext: solid_js.Context<RouterContextValue | null>;
|
|
104
|
-
declare const RouteContext: solid_js.Context<Accessor<RouteState<_real_router_core.Params
|
|
104
|
+
declare const RouteContext: solid_js.Context<Accessor<RouteState<_real_router_core.Params>> | null>;
|
|
105
105
|
|
|
106
106
|
declare function createSignalFromSource<T>(source: RouterSource<T>): Accessor<T>;
|
|
107
107
|
|
package/dist/esm/index.mjs
CHANGED
|
@@ -146,7 +146,7 @@ const RouteView = Object.assign(RouteViewRoot, {
|
|
|
146
146
|
NotFound
|
|
147
147
|
});
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
const e=`data-real-router-announcer`;function t(e,t){let o=`Navigated to `,c=true,l=false,u=false,d=``,f,p=n(),m=setTimeout(()=>{l=true;},100),h=e.subscribe(({route:e})=>{if(c){c=false;return}requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(u)return;let t=i(e,o);t&&t!==d&&l&&(d=t,clearTimeout(f),p.textContent=t,f=setTimeout(()=>{p.textContent=``,d=``;},7e3),a());});});});return {destroy(){u=true,h(),clearTimeout(f),clearTimeout(m),r();}}}function n(){let t=document.querySelector(`[${e}]`);if(t)return t;let n=document.createElement(`div`);return n.setAttribute(`style`,`position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);clip-path:inset(50%);white-space:nowrap;border:0`),n.setAttribute(`aria-live`,`assertive`),n.setAttribute(`aria-atomic`,`true`),n.setAttribute(e,``),document.body.prepend(n),n}function r(){document.querySelector(`[${e}]`)?.remove();}function i(e,t,n){let r=document.querySelector(`h1`)?.textContent.trim()??``,i=e.name.startsWith(`@@`)?``:e.name;return `${t}${r||document.title||i||globalThis.location.pathname}`}function a(){let e=document.querySelector(`h1`);e&&(e.hasAttribute(`tabindex`)||e.setAttribute(`tabindex`,`-1`),e.focus({preventScroll:true}));}function o(e){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey}function s(e,t,n){try{let r=e.buildUrl;return r?r(t,n):e.buildPath(t,n)}catch{console.error(`[real-router] Route "${t}" is not defined. The element will render without an href attribute.`);return}}function c(e,t,n){return e&&t?n?`${n} ${t}`.trim():t:n??void 0}function l(e){e instanceof HTMLAnchorElement||e instanceof HTMLButtonElement||(e.getAttribute(`role`)||e.setAttribute(`role`,`link`),e.getAttribute(`tabindex`)||e.setAttribute(`tabindex`,`0`));}
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* Stable empty object for default params
|
|
@@ -175,7 +175,7 @@ function Link(props) {
|
|
|
175
175
|
strict: local.activeStrict,
|
|
176
176
|
ignoreQueryParams: local.ignoreQueryParams
|
|
177
177
|
}));
|
|
178
|
-
const href = createMemo(() =>
|
|
178
|
+
const href = createMemo(() => s(router, local.routeName, local.routeParams));
|
|
179
179
|
const handleClick = evt => {
|
|
180
180
|
if (local.onClick) {
|
|
181
181
|
local.onClick(evt);
|
|
@@ -183,13 +183,13 @@ function Link(props) {
|
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
if (!
|
|
186
|
+
if (!o(evt) || local.target === "_blank") {
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
189
189
|
evt.preventDefault();
|
|
190
190
|
router.navigate(local.routeName, local.routeParams, local.routeOptions).catch(() => {});
|
|
191
191
|
};
|
|
192
|
-
const finalClassName = createMemo(() =>
|
|
192
|
+
const finalClassName = createMemo(() => c(isActive(), local.activeClassName, local.class));
|
|
193
193
|
return (() => {
|
|
194
194
|
var _el$ = _tmpl$();
|
|
195
195
|
spread(_el$, mergeProps$1(rest, {
|
|
@@ -243,9 +243,14 @@ function link(element, accessor) {
|
|
|
243
243
|
|
|
244
244
|
// Set href on <a> elements
|
|
245
245
|
if (element instanceof HTMLAnchorElement) {
|
|
246
|
-
|
|
246
|
+
const href = s(router, options.routeName, options.routeParams ?? EMPTY_PARAMS);
|
|
247
|
+
if (href === undefined) {
|
|
248
|
+
element.removeAttribute("href");
|
|
249
|
+
} else {
|
|
250
|
+
element.href = href;
|
|
251
|
+
}
|
|
247
252
|
}
|
|
248
|
-
|
|
253
|
+
l(element);
|
|
249
254
|
|
|
250
255
|
// Active class tracking (reactive)
|
|
251
256
|
if (options.activeClassName) {
|
|
@@ -262,7 +267,7 @@ function link(element, accessor) {
|
|
|
262
267
|
|
|
263
268
|
// Click handler
|
|
264
269
|
function handleClick(evt) {
|
|
265
|
-
if (!
|
|
270
|
+
if (!o(evt)) {
|
|
266
271
|
return;
|
|
267
272
|
}
|
|
268
273
|
if (element instanceof HTMLAnchorElement) {
|
|
@@ -334,7 +339,7 @@ function RouterProvider(props) {
|
|
|
334
339
|
if (!props.announceNavigation) {
|
|
335
340
|
return;
|
|
336
341
|
}
|
|
337
|
-
const announcer =
|
|
342
|
+
const announcer = t(props.router);
|
|
338
343
|
onCleanup(() => {
|
|
339
344
|
announcer.destroy();
|
|
340
345
|
});
|
package/dist/types/context.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export interface RouterContextValue {
|
|
|
7
7
|
routeSelector: (routeName: string) => boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare const RouterContext: import("solid-js", { with: { "resolution-mode": "import" } }).Context<RouterContextValue | null>;
|
|
10
|
-
export declare const RouteContext: import("solid-js", { with: { "resolution-mode": "import" } }).Context<Accessor<RouteState<import("@real-router/core").Params
|
|
10
|
+
export declare const RouteContext: import("solid-js", { with: { "resolution-mode": "import" } }).Context<Accessor<RouteState<import("@real-router/core").Params>> | null>;
|
|
11
11
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;CAC/C;AAED,eAAO,MAAM,aAAa,kGAAiD,CAAC;AAE5E,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;CAC/C;AAED,eAAO,MAAM,aAAa,kGAAiD,CAAC;AAE5E,eAAO,MAAM,YAAY,wIAAmD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/directives/link.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC7D,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,CAAC,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAC5C,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,MAAM,oBAAoB,CAAC,CAAC,CAAC,GACtC,IAAI,
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/directives/link.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC7D,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,CAAC,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAC5C,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,MAAM,oBAAoB,CAAC,CAAC,CAAC,GACtC,IAAI,CA+DN"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NavigationOptions, Params, State } from "@real-router/core";
|
|
2
2
|
import type { JSX } from "solid-js";
|
|
3
|
-
export interface RouteState<P extends Params = Params
|
|
4
|
-
route: State<P
|
|
3
|
+
export interface RouteState<P extends Params = Params> {
|
|
4
|
+
route: State<P> | undefined;
|
|
5
5
|
previousRoute?: State | undefined;
|
|
6
6
|
}
|
|
7
7
|
export interface LinkProps<P extends Params = Params> extends Omit<JSX.HTMLAttributes<HTMLAnchorElement>, "onClick"> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,WAAW,UAAU,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACnD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAC5B,aAAa,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,IAAI,CAChE,GAAG,CAAC,cAAc,CAAC,iBAAiB,CAAC,EACrC,SAAS,CACV;IACC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,CAAC,CAAC;IAChB,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,IAAI,CAAC;CACrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@real-router/solid",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "Solid.js integration for Real-Router",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
"license": "MIT",
|
|
52
52
|
"sideEffects": false,
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@real-router/
|
|
55
|
-
"@real-router/
|
|
56
|
-
"@real-router/sources": "^0.3.
|
|
57
|
-
"dom-utils": "^0.2.
|
|
54
|
+
"@real-router/core": "^0.41.0",
|
|
55
|
+
"@real-router/route-utils": "^0.1.7",
|
|
56
|
+
"@real-router/sources": "^0.3.1",
|
|
57
|
+
"dom-utils": "^0.2.3"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@babel/core": "7.29.0",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"solid-js": "1.9.5",
|
|
73
73
|
"vite-plugin-solid": "2.11.11",
|
|
74
74
|
"vitest": "4.1.0",
|
|
75
|
-
"@real-router/browser-plugin": "^0.
|
|
75
|
+
"@real-router/browser-plugin": "^0.11.0"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"solid-js": ">=1.7.0"
|
package/src/directives/link.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createActiveRouteSource } from "@real-router/sources";
|
|
2
|
-
import { shouldNavigate, applyLinkA11y } from "dom-utils";
|
|
2
|
+
import { shouldNavigate, applyLinkA11y, buildHref } from "dom-utils";
|
|
3
3
|
import { createEffect, onCleanup } from "solid-js";
|
|
4
4
|
|
|
5
5
|
import { EMPTY_PARAMS, EMPTY_OPTIONS } from "../constants";
|
|
@@ -26,10 +26,17 @@ export function link<P extends Params = Params>(
|
|
|
26
26
|
|
|
27
27
|
// Set href on <a> elements
|
|
28
28
|
if (element instanceof HTMLAnchorElement) {
|
|
29
|
-
|
|
29
|
+
const href = buildHref(
|
|
30
|
+
router,
|
|
30
31
|
options.routeName,
|
|
31
32
|
options.routeParams ?? (EMPTY_PARAMS as P),
|
|
32
33
|
);
|
|
34
|
+
|
|
35
|
+
if (href === undefined) {
|
|
36
|
+
element.removeAttribute("href");
|
|
37
|
+
} else {
|
|
38
|
+
element.href = href;
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
applyLinkA11y(element);
|
package/src/types.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { NavigationOptions, Params, State } from "@real-router/core";
|
|
2
2
|
import type { JSX } from "solid-js";
|
|
3
3
|
|
|
4
|
-
export interface RouteState<
|
|
5
|
-
P
|
|
6
|
-
MP extends Params = Params,
|
|
7
|
-
> {
|
|
8
|
-
route: State<P, MP> | undefined;
|
|
4
|
+
export interface RouteState<P extends Params = Params> {
|
|
5
|
+
route: State<P> | undefined;
|
|
9
6
|
previousRoute?: State | undefined;
|
|
10
7
|
}
|
|
11
8
|
|