@solidjs/router 0.8.4 → 0.9.0
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/README.md +2 -0
- package/dist/components.jsx +6 -2
- package/dist/index.js +7 -4
- package/dist/routing.js +3 -1
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
# Solid Router [](https://www.npmjs.org/package/@solidjs/router)
|
|
6
6
|
|
|
7
|
+
#### Note: v0.9.0 requires Solid 1.8.4 or later
|
|
8
|
+
|
|
7
9
|
A router lets you change your view based on the URL in the browser. This allows your "single-page" application to simulate a traditional multipage site. To use Solid Router, you specify components called Routes that depend on the value of the URL (the "path"), and the router handles the mechanism of swapping them in and out.
|
|
8
10
|
|
|
9
11
|
Solid Router is a universal router for SolidJS - it works whether you're rendering on the client or on the server. It was inspired by and combines paradigms of React Router and the Ember Router. Routes can be defined directly in your app's template using JSX, but you can also pass your route configuration directly as an object. It also supports nested routing, so navigation can change a part of a component, rather than completely replacing it.
|
package/dist/components.jsx
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/*@refresh skip*/
|
|
2
2
|
import { children, createMemo, createRoot, mergeProps, on, Show, splitProps } from "solid-js";
|
|
3
|
-
import { isServer } from "solid-js/web";
|
|
3
|
+
import { isServer, getRequestEvent } from "solid-js/web";
|
|
4
4
|
import { pathIntegration, staticIntegration } from "./integration";
|
|
5
5
|
import { createBranches, createRouteContext, createRouterContext, getRouteMatches, RouteContextObj, RouterContextObj, useHref, useLocation, useNavigate, useResolvedPath, useRoute, useRouter } from "./routing";
|
|
6
6
|
import { joinPaths, normalizePath, createMemoObject } from "./utils";
|
|
7
7
|
export const Router = (props) => {
|
|
8
|
+
let e;
|
|
8
9
|
const { source, url, base, data, out } = props;
|
|
9
|
-
const integration = source ||
|
|
10
|
+
const integration = source ||
|
|
11
|
+
(isServer
|
|
12
|
+
? staticIntegration({ value: url || ((e = getRequestEvent()) && e.request.url) || "" })
|
|
13
|
+
: pathIntegration());
|
|
10
14
|
const routerState = createRouterContext(integration, base, data, out);
|
|
11
15
|
return (<RouterContextObj.Provider value={routerState}>{props.children}</RouterContextObj.Provider>);
|
|
12
16
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isServer, delegateEvents, createComponent as createComponent$1, spread, mergeProps as mergeProps$1, template } from 'solid-js/web';
|
|
1
|
+
import { isServer, delegateEvents, getRequestEvent, createComponent as createComponent$1, spread, mergeProps as mergeProps$1, template } from 'solid-js/web';
|
|
2
2
|
import { createSignal, onCleanup, getOwner, runWithOwner, createMemo, createContext, useContext, untrack, createRenderEffect, createComponent, on, startTransition, resetErrorBoundaries, children, createRoot, Show, mergeProps, splitProps } from 'solid-js';
|
|
3
3
|
|
|
4
4
|
function bindEvent(target, type, handler) {
|
|
@@ -617,6 +617,8 @@ function createRouterContext(integration, base = "", data, out) {
|
|
|
617
617
|
if (output) {
|
|
618
618
|
output.url = resolvedTo;
|
|
619
619
|
}
|
|
620
|
+
const e = getRequestEvent();
|
|
621
|
+
e && (e.response = Response.redirect(resolvedTo, 302));
|
|
620
622
|
setSource({
|
|
621
623
|
value: resolvedTo,
|
|
622
624
|
replace,
|
|
@@ -761,8 +763,9 @@ function createRouteContext(router, parent, child, match, params) {
|
|
|
761
763
|
return route;
|
|
762
764
|
}
|
|
763
765
|
|
|
764
|
-
const _tmpl$ = /*#__PURE__*/template(`<a link
|
|
766
|
+
const _tmpl$ = /*#__PURE__*/template(`<a link>`);
|
|
765
767
|
const Router = props => {
|
|
768
|
+
let e;
|
|
766
769
|
const {
|
|
767
770
|
source,
|
|
768
771
|
url,
|
|
@@ -771,7 +774,7 @@ const Router = props => {
|
|
|
771
774
|
out
|
|
772
775
|
} = props;
|
|
773
776
|
const integration = source || (isServer ? staticIntegration({
|
|
774
|
-
value: url || ""
|
|
777
|
+
value: url || (e = getRequestEvent()) && e.request.url || ""
|
|
775
778
|
}) : pathIntegration());
|
|
776
779
|
const routerState = createRouterContext(integration, base, data, out);
|
|
777
780
|
return createComponent$1(RouterContextObj.Provider, {
|
|
@@ -894,7 +897,7 @@ function A(props) {
|
|
|
894
897
|
return props.end ? path === loc : loc.startsWith(path);
|
|
895
898
|
});
|
|
896
899
|
return (() => {
|
|
897
|
-
const _el$ = _tmpl
|
|
900
|
+
const _el$ = _tmpl$();
|
|
898
901
|
spread(_el$, mergeProps$1(rest, {
|
|
899
902
|
get href() {
|
|
900
903
|
return href() || props.href;
|
package/dist/routing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent, createContext, createMemo, createRenderEffect, createSignal, on, onCleanup, untrack, useContext, startTransition, resetErrorBoundaries } from "solid-js";
|
|
2
|
-
import { isServer, delegateEvents } from "solid-js/web";
|
|
2
|
+
import { isServer, delegateEvents, getRequestEvent } from "solid-js/web";
|
|
3
3
|
import { normalizeIntegration } from "./integration";
|
|
4
4
|
import { createBeforeLeave } from "./lifecycle";
|
|
5
5
|
import { createMemoObject, extractSearchParams, invariant, resolvePath, createMatcher, joinPaths, scoreRoute, mergeSearchString, expandOptionals } from "./utils";
|
|
@@ -271,6 +271,8 @@ export function createRouterContext(integration, base = "", data, out) {
|
|
|
271
271
|
if (output) {
|
|
272
272
|
output.url = resolvedTo;
|
|
273
273
|
}
|
|
274
|
+
const e = getRequestEvent();
|
|
275
|
+
e && (e.response = Response.redirect(resolvedTo, 302));
|
|
274
276
|
setSource({ value: resolvedTo, replace, scroll, state: nextState });
|
|
275
277
|
}
|
|
276
278
|
else if (beforeLeave.confirm(resolvedTo, options)) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { Component, JSX } from "solid-js";
|
|
2
|
+
declare module "solid-js/web" {
|
|
3
|
+
interface RequestEvent {
|
|
4
|
+
response?: Response;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
2
7
|
export type Params = Record<string, string>;
|
|
3
8
|
export type SetParams = Record<string, string | number | boolean | null | undefined>;
|
|
4
9
|
export interface Path {
|