|
1 | 1 | import { getQueriesForElement, prettyDOM } from "@testing-library/dom"; |
2 | 2 | import { |
3 | 3 | Accessor, |
4 | | - children, |
5 | 4 | createComponent, |
6 | 5 | createRoot, |
7 | 6 | createSignal, |
8 | 7 | getOwner, |
| 8 | + lazy, |
9 | 9 | onError, |
10 | 10 | onMount, |
11 | 11 | Owner, |
12 | | - runWithOwner, |
| 12 | + runWithOwner |
13 | 13 | } from "solid-js"; |
14 | 14 | import { hydrate as solidHydrate, render as solidRender } from "solid-js/web"; |
15 | 15 |
|
16 | | -import { Router, Navigate, memoryIntegration, useParams } from "@solidjs/router"; |
17 | | - |
18 | 16 | import type { |
19 | 17 | Ui, |
20 | 18 | Result, |
@@ -86,19 +84,36 @@ function render(ui: Ui, options: Options = {}): Result { |
86 | 84 | }) |
87 | 85 | : ui; |
88 | 86 |
|
89 | | - const routedUi: Ui = () => { |
90 | | - return !location ? wrappedUi() : createComponent(Router, { |
91 | | - get children() { |
92 | | - return [ |
93 | | - createComponent(Navigate, { href: location || "" }), |
94 | | - createComponent(wrappedUi, {}) |
95 | | - ] |
96 | | - }, |
97 | | - get source() { |
98 | | - return memoryIntegration(); |
99 | | - } |
100 | | - }); |
101 | | - }; |
| 87 | + const routedUi: Ui = |
| 88 | + typeof location === "string" |
| 89 | + ? lazy(async () => { |
| 90 | + try { |
| 91 | + const { memoryIntegration, useNavigate, Router } = await import("@solidjs/router"); |
| 92 | + return { |
| 93 | + default: () => |
| 94 | + createComponent(Router, { |
| 95 | + get children() { |
| 96 | + return [ |
| 97 | + createComponent( |
| 98 | + () => (useNavigate()(location || "", { replace: true, scroll: false }), null), |
| 99 | + {} |
| 100 | + ), |
| 101 | + createComponent(wrappedUi, {}) |
| 102 | + ]; |
| 103 | + }, |
| 104 | + get source() { |
| 105 | + return memoryIntegration(); |
| 106 | + } |
| 107 | + }) |
| 108 | + }; |
| 109 | + } catch (e) { |
| 110 | + console.error( |
| 111 | + "It appears you want to use the location option without having @solidjs/router installed." |
| 112 | + ); |
| 113 | + return { default: () => createComponent(wrappedUi, {}) }; |
| 114 | + } |
| 115 | + }) |
| 116 | + : wrappedUi; |
102 | 117 |
|
103 | 118 | const dispose = hydrate |
104 | 119 | ? (solidHydrate(routedUi, container) as unknown as () => void) |
|
0 commit comments