@solidjs/router 0.8.3 → 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 CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  # Solid Router [![npm Version](https://img.shields.io/npm/v/@solidjs/router.svg?style=flat-square)](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.
@@ -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 || (isServer ? staticIntegration({ value: url || "" }) : pathIntegration());
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) {
@@ -9,6 +9,9 @@ function intercept([value, setValue], get, set) {
9
9
  return [get ? () => get(value()) : value, set ? v => setValue(set(v)) : setValue];
10
10
  }
11
11
  function querySelector(selector) {
12
+ if (selector === "#") {
13
+ return null;
14
+ }
12
15
  // Guard against selector being an invalid CSS selector
13
16
  try {
14
17
  return document.querySelector(selector);
@@ -614,6 +617,8 @@ function createRouterContext(integration, base = "", data, out) {
614
617
  if (output) {
615
618
  output.url = resolvedTo;
616
619
  }
620
+ const e = getRequestEvent();
621
+ e && (e.response = Response.redirect(resolvedTo, 302));
617
622
  setSource({
618
623
  value: resolvedTo,
619
624
  replace,
@@ -758,8 +763,9 @@ function createRouteContext(router, parent, child, match, params) {
758
763
  return route;
759
764
  }
760
765
 
761
- const _tmpl$ = /*#__PURE__*/template(`<a link></a>`, 2);
766
+ const _tmpl$ = /*#__PURE__*/template(`<a link>`);
762
767
  const Router = props => {
768
+ let e;
763
769
  const {
764
770
  source,
765
771
  url,
@@ -768,7 +774,7 @@ const Router = props => {
768
774
  out
769
775
  } = props;
770
776
  const integration = source || (isServer ? staticIntegration({
771
- value: url || ""
777
+ value: url || (e = getRequestEvent()) && e.request.url || ""
772
778
  }) : pathIntegration());
773
779
  const routerState = createRouterContext(integration, base, data, out);
774
780
  return createComponent$1(RouterContextObj.Provider, {
@@ -891,7 +897,7 @@ function A(props) {
891
897
  return props.end ? path === loc : loc.startsWith(path);
892
898
  });
893
899
  return (() => {
894
- const _el$ = _tmpl$.cloneNode(true);
900
+ const _el$ = _tmpl$();
895
901
  spread(_el$, mergeProps$1(rest, {
896
902
  get href() {
897
903
  return href() || props.href;
@@ -7,6 +7,9 @@ function intercept([value, setValue], get, set) {
7
7
  return [get ? () => get(value()) : value, set ? (v) => setValue(set(v)) : setValue];
8
8
  }
9
9
  function querySelector(selector) {
10
+ if (selector === "#") {
11
+ return null;
12
+ }
10
13
  // Guard against selector being an invalid CSS selector
11
14
  try {
12
15
  return document.querySelector(selector);
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 {
@@ -53,7 +58,7 @@ export type RouteDefinition<S extends string | string[] = any> = {
53
58
  element?: JSX.Element;
54
59
  preload?: () => void;
55
60
  });
56
- export type MatchFilter = string[] | RegExp | ((s: string) => boolean);
61
+ export type MatchFilter = readonly string[] | RegExp | ((s: string) => boolean);
57
62
  export type PathParams<P extends string | readonly string[]> = P extends `${infer Head}/${infer Tail}` ? [...PathParams<Head>, ...PathParams<Tail>] : P extends `:${infer S}?` ? [S] : P extends `:${infer S}` ? [S] : P extends `*${infer S}` ? [S] : [];
58
63
  export type MatchFilters<P extends string | readonly string[] = any> = P extends string ? {
59
64
  [K in PathParams<P>[number]]?: MatchFilter;
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "Ryan Turnquist"
7
7
  ],
8
8
  "license": "MIT",
9
- "version": "0.8.3",
9
+ "version": "0.9.0",
10
10
  "homepage": "https://github.com/solidjs/solid-router#readme",
11
11
  "repository": {
12
12
  "type": "git",