one 1.2.20 → 1.2.22
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/cli/build.cjs +11 -2
- package/dist/cjs/cli/build.js +10 -2
- package/dist/cjs/cli/build.js.map +1 -1
- package/dist/cjs/cli/build.native.js +44 -19
- package/dist/cjs/cli/build.native.js.map +1 -1
- package/dist/cjs/cli/buildPage.cjs +3 -2
- package/dist/cjs/cli/buildPage.js +3 -2
- package/dist/cjs/cli/buildPage.js.map +1 -1
- package/dist/cjs/cli/buildPage.native.js +3 -2
- package/dist/cjs/cli/buildPage.native.js.map +1 -1
- package/dist/cjs/createApp.cjs +23 -16
- package/dist/cjs/createApp.js +73 -67
- package/dist/cjs/createApp.js.map +2 -2
- package/dist/cjs/createHandleRequest.cjs +10 -6
- package/dist/cjs/createHandleRequest.js +10 -6
- package/dist/cjs/createHandleRequest.js.map +1 -1
- package/dist/cjs/createHandleRequest.native.js +11 -7
- package/dist/cjs/createHandleRequest.native.js.map +1 -1
- package/dist/cjs/fork/NavigationContainer.cjs +1 -1
- package/dist/cjs/fork/NavigationContainer.js +4 -1
- package/dist/cjs/fork/NavigationContainer.js.map +1 -1
- package/dist/cjs/fork/NavigationContainer.native.js +1 -1
- package/dist/cjs/fork/NavigationContainer.native.js.map +1 -1
- package/dist/cjs/fork/createMemoryHistory.cjs +2 -2
- package/dist/cjs/fork/createMemoryHistory.js +2 -2
- package/dist/cjs/fork/createMemoryHistory.js.map +1 -1
- package/dist/cjs/fork/createMemoryHistory.native.js +2 -2
- package/dist/cjs/fork/createMemoryHistory.native.js.map +1 -1
- package/dist/cjs/fork/extractPathFromURL.cjs +1 -1
- package/dist/cjs/fork/extractPathFromURL.js +1 -1
- package/dist/cjs/fork/extractPathFromURL.js.map +1 -1
- package/dist/cjs/fork/extractPathFromURL.native.js +1 -1
- package/dist/cjs/fork/extractPathFromURL.native.js.map +1 -1
- package/dist/cjs/fork/getPathFromState-mods.cjs +1 -1
- package/dist/cjs/fork/getPathFromState-mods.js +1 -1
- package/dist/cjs/fork/getPathFromState-mods.js.map +1 -1
- package/dist/cjs/fork/getPathFromState-mods.native.js +1 -1
- package/dist/cjs/fork/getPathFromState-mods.native.js.map +1 -1
- package/dist/cjs/fork/getStateFromPath-mods.cjs +20 -19
- package/dist/cjs/fork/getStateFromPath-mods.js +18 -15
- package/dist/cjs/fork/getStateFromPath-mods.js.map +1 -1
- package/dist/cjs/fork/getStateFromPath-mods.native.js +19 -18
- package/dist/cjs/fork/getStateFromPath-mods.native.js.map +1 -1
- package/dist/cjs/fork/getStateFromPath.cjs +1 -1
- package/dist/cjs/fork/getStateFromPath.js +1 -1
- package/dist/cjs/fork/getStateFromPath.js.map +1 -1
- package/dist/cjs/fork/getStateFromPath.native.js +1 -1
- package/dist/cjs/fork/getStateFromPath.native.js.map +1 -1
- package/dist/cjs/fork/useLinking.cjs +26 -19
- package/dist/cjs/fork/useLinking.js +31 -19
- package/dist/cjs/fork/useLinking.js.map +2 -2
- package/dist/cjs/fork/useLinking.native.js +2 -1
- package/dist/cjs/fork/useLinking.native.js.map +1 -1
- package/dist/cjs/getReactNavigationConfig.cjs +2 -4
- package/dist/cjs/getReactNavigationConfig.js +2 -5
- package/dist/cjs/getReactNavigationConfig.js.map +1 -1
- package/dist/cjs/getReactNavigationConfig.native.js +2 -4
- package/dist/cjs/getReactNavigationConfig.native.js.map +1 -1
- package/dist/cjs/hooks.cjs +1 -1
- package/dist/cjs/hooks.js +1 -1
- package/dist/cjs/hooks.js.map +1 -1
- package/dist/cjs/hooks.native.js +4 -1
- package/dist/cjs/hooks.native.js.map +1 -1
- package/dist/cjs/router/getRoutes.cjs +4 -5
- package/dist/cjs/router/getRoutes.js +2 -2
- package/dist/cjs/router/getRoutes.js.map +1 -1
- package/dist/cjs/router/getRoutes.native.js +4 -5
- package/dist/cjs/router/getRoutes.native.js.map +1 -1
- package/dist/cjs/router/matchers.cjs +9 -1
- package/dist/cjs/router/matchers.js +4 -1
- package/dist/cjs/router/matchers.js.map +1 -1
- package/dist/cjs/router/matchers.native.js +10 -2
- package/dist/cjs/router/matchers.native.js.map +1 -1
- package/dist/cjs/router/matchers.test.cjs +7 -1
- package/dist/cjs/router/matchers.test.js +1 -1
- package/dist/cjs/router/matchers.test.js.map +1 -1
- package/dist/cjs/router/matchers.test.native.js +7 -1
- package/dist/cjs/router/matchers.test.native.js.map +1 -1
- package/dist/cjs/router/router.cjs +6 -6
- package/dist/cjs/router/router.js +6 -6
- package/dist/cjs/router/router.js.map +1 -1
- package/dist/cjs/router/router.native.js +6 -6
- package/dist/cjs/router/router.native.js.map +1 -1
- package/dist/cjs/router/useViteRoutes.cjs +12 -17
- package/dist/cjs/router/useViteRoutes.js +12 -17
- package/dist/cjs/router/useViteRoutes.js.map +2 -2
- package/dist/cjs/router/useViteRoutes.native.js +12 -0
- package/dist/cjs/router/useViteRoutes.native.js.map +1 -1
- package/dist/cjs/router/utils/getNavigateAction.cjs +2 -2
- package/dist/cjs/router/utils/getNavigateAction.js +2 -2
- package/dist/cjs/router/utils/getNavigateAction.js.map +1 -1
- package/dist/cjs/router/utils/getNavigateAction.native.js +2 -2
- package/dist/cjs/router/utils/getNavigateAction.native.js.map +1 -1
- package/dist/cjs/server/oneServe.cjs +4 -3
- package/dist/cjs/server/oneServe.js +6 -3
- package/dist/cjs/server/oneServe.js.map +1 -1
- package/dist/cjs/server/oneServe.native.js +5 -4
- package/dist/cjs/server/oneServe.native.js.map +1 -1
- package/dist/cjs/vite/one.cjs +9 -12
- package/dist/cjs/vite/one.js +7 -7
- package/dist/cjs/vite/one.js.map +1 -1
- package/dist/cjs/vite/one.native.js +10 -15
- package/dist/cjs/vite/one.native.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +12 -7
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +11 -7
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +12 -7
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/esm/cli/build.js +10 -2
- package/dist/esm/cli/build.js.map +1 -1
- package/dist/esm/cli/build.mjs +11 -2
- package/dist/esm/cli/build.mjs.map +1 -1
- package/dist/esm/cli/build.native.js +44 -19
- package/dist/esm/cli/build.native.js.map +1 -1
- package/dist/esm/cli/buildPage.js +3 -2
- package/dist/esm/cli/buildPage.js.map +1 -1
- package/dist/esm/cli/buildPage.mjs +3 -2
- package/dist/esm/cli/buildPage.mjs.map +1 -1
- package/dist/esm/cli/buildPage.native.js +3 -2
- package/dist/esm/cli/buildPage.native.js.map +1 -1
- package/dist/esm/createApp.js +73 -66
- package/dist/esm/createApp.js.map +2 -2
- package/dist/esm/createApp.mjs +23 -16
- package/dist/esm/createApp.mjs.map +1 -1
- package/dist/esm/createHandleRequest.js +10 -6
- package/dist/esm/createHandleRequest.js.map +1 -1
- package/dist/esm/createHandleRequest.mjs +10 -6
- package/dist/esm/createHandleRequest.mjs.map +1 -1
- package/dist/esm/createHandleRequest.native.js +10 -6
- package/dist/esm/createHandleRequest.native.js.map +1 -1
- package/dist/esm/fork/NavigationContainer.js +4 -1
- package/dist/esm/fork/NavigationContainer.js.map +1 -1
- package/dist/esm/fork/NavigationContainer.mjs +1 -1
- package/dist/esm/fork/NavigationContainer.mjs.map +1 -1
- package/dist/esm/fork/NavigationContainer.native.js +1 -1
- package/dist/esm/fork/NavigationContainer.native.js.map +1 -1
- package/dist/esm/fork/createMemoryHistory.js +2 -2
- package/dist/esm/fork/createMemoryHistory.js.map +1 -1
- package/dist/esm/fork/createMemoryHistory.mjs +2 -2
- package/dist/esm/fork/createMemoryHistory.mjs.map +1 -1
- package/dist/esm/fork/createMemoryHistory.native.js +2 -2
- package/dist/esm/fork/createMemoryHistory.native.js.map +1 -1
- package/dist/esm/fork/extractPathFromURL.js +1 -1
- package/dist/esm/fork/extractPathFromURL.js.map +1 -1
- package/dist/esm/fork/extractPathFromURL.mjs +1 -1
- package/dist/esm/fork/extractPathFromURL.mjs.map +1 -1
- package/dist/esm/fork/extractPathFromURL.native.js +1 -1
- package/dist/esm/fork/extractPathFromURL.native.js.map +1 -1
- package/dist/esm/fork/getPathFromState-mods.js +2 -2
- package/dist/esm/fork/getPathFromState-mods.js.map +1 -1
- package/dist/esm/fork/getPathFromState-mods.mjs +2 -2
- package/dist/esm/fork/getPathFromState-mods.mjs.map +1 -1
- package/dist/esm/fork/getPathFromState-mods.native.js +2 -2
- package/dist/esm/fork/getPathFromState-mods.native.js.map +1 -1
- package/dist/esm/fork/getStateFromPath-mods.js +18 -15
- package/dist/esm/fork/getStateFromPath-mods.js.map +1 -1
- package/dist/esm/fork/getStateFromPath-mods.mjs +20 -19
- package/dist/esm/fork/getStateFromPath-mods.mjs.map +1 -1
- package/dist/esm/fork/getStateFromPath-mods.native.js +19 -18
- package/dist/esm/fork/getStateFromPath-mods.native.js.map +1 -1
- package/dist/esm/fork/getStateFromPath.js +1 -1
- package/dist/esm/fork/getStateFromPath.js.map +1 -1
- package/dist/esm/fork/getStateFromPath.mjs +1 -1
- package/dist/esm/fork/getStateFromPath.mjs.map +1 -1
- package/dist/esm/fork/getStateFromPath.native.js +1 -1
- package/dist/esm/fork/useLinking.js +31 -18
- package/dist/esm/fork/useLinking.js.map +1 -1
- package/dist/esm/fork/useLinking.mjs +26 -19
- package/dist/esm/fork/useLinking.mjs.map +1 -1
- package/dist/esm/fork/useLinking.native.js +2 -1
- package/dist/esm/fork/useLinking.native.js.map +1 -1
- package/dist/esm/getReactNavigationConfig.js +3 -6
- package/dist/esm/getReactNavigationConfig.js.map +1 -1
- package/dist/esm/getReactNavigationConfig.mjs +3 -5
- package/dist/esm/getReactNavigationConfig.mjs.map +1 -1
- package/dist/esm/getReactNavigationConfig.native.js +3 -5
- package/dist/esm/getReactNavigationConfig.native.js.map +1 -1
- package/dist/esm/hooks.js +1 -1
- package/dist/esm/hooks.js.map +1 -1
- package/dist/esm/hooks.mjs +1 -1
- package/dist/esm/hooks.mjs.map +1 -1
- package/dist/esm/hooks.native.js +4 -1
- package/dist/esm/hooks.native.js.map +1 -1
- package/dist/esm/router/getRoutes.js +2 -3
- package/dist/esm/router/getRoutes.js.map +1 -1
- package/dist/esm/router/getRoutes.mjs +5 -6
- package/dist/esm/router/getRoutes.mjs.map +1 -1
- package/dist/esm/router/getRoutes.native.js +5 -6
- package/dist/esm/router/getRoutes.native.js.map +1 -1
- package/dist/esm/router/matchers.js +4 -1
- package/dist/esm/router/matchers.js.map +1 -1
- package/dist/esm/router/matchers.mjs +9 -1
- package/dist/esm/router/matchers.mjs.map +1 -1
- package/dist/esm/router/matchers.native.js +10 -2
- package/dist/esm/router/matchers.native.js.map +1 -1
- package/dist/esm/router/matchers.test.js +1 -1
- package/dist/esm/router/matchers.test.js.map +1 -1
- package/dist/esm/router/matchers.test.mjs +7 -1
- package/dist/esm/router/matchers.test.mjs.map +1 -1
- package/dist/esm/router/matchers.test.native.js +7 -1
- package/dist/esm/router/matchers.test.native.js.map +1 -1
- package/dist/esm/router/router.js +6 -6
- package/dist/esm/router/router.js.map +1 -1
- package/dist/esm/router/router.mjs +6 -6
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +6 -6
- package/dist/esm/router/router.native.js.map +1 -1
- package/dist/esm/router/useViteRoutes.js +12 -17
- package/dist/esm/router/useViteRoutes.js.map +1 -1
- package/dist/esm/router/useViteRoutes.mjs +11 -18
- package/dist/esm/router/useViteRoutes.mjs.map +1 -1
- package/dist/esm/router/useViteRoutes.native.js +11 -1
- package/dist/esm/router/useViteRoutes.native.js.map +1 -1
- package/dist/esm/router/utils/getNavigateAction.js +2 -2
- package/dist/esm/router/utils/getNavigateAction.js.map +1 -1
- package/dist/esm/router/utils/getNavigateAction.mjs +2 -2
- package/dist/esm/router/utils/getNavigateAction.mjs.map +1 -1
- package/dist/esm/router/utils/getNavigateAction.native.js +2 -2
- package/dist/esm/router/utils/getNavigateAction.native.js.map +1 -1
- package/dist/esm/server/oneServe.js +6 -3
- package/dist/esm/server/oneServe.js.map +1 -1
- package/dist/esm/server/oneServe.mjs +4 -3
- package/dist/esm/server/oneServe.mjs.map +1 -1
- package/dist/esm/server/oneServe.native.js +4 -3
- package/dist/esm/server/oneServe.native.js.map +1 -1
- package/dist/esm/vite/one.js +9 -9
- package/dist/esm/vite/one.js.map +1 -1
- package/dist/esm/vite/one.mjs +9 -12
- package/dist/esm/vite/one.mjs.map +1 -1
- package/dist/esm/vite/one.native.js +10 -15
- package/dist/esm/vite/one.native.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +11 -7
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +12 -7
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +12 -7
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/package.json +9 -9
- package/src/cli/build.ts +26 -1
- package/src/cli/buildPage.ts +3 -1
- package/src/createApp.tsx +28 -21
- package/src/createHandleRequest.ts +34 -0
- package/src/fork/NavigationContainer.tsx +8 -0
- package/src/fork/createMemoryHistory.tsx +8 -0
- package/src/fork/extractPathFromURL.ts +6 -0
- package/src/fork/getPathFromState-mods.ts +2 -7
- package/src/fork/getStateFromPath-mods.ts +43 -17
- package/src/fork/getStateFromPath.ts +1 -1
- package/src/fork/useLinking.native.ts +1 -1
- package/src/fork/useLinking.ts +80 -5
- package/src/getReactNavigationConfig.ts +7 -9
- package/src/hooks.tsx +21 -19
- package/src/router/getRoutes.ts +3 -6
- package/src/router/matchers.test.ts +2 -2
- package/src/router/matchers.ts +22 -6
- package/src/router/router.ts +6 -6
- package/src/router/useViteRoutes.tsx +19 -17
- package/src/router/utils/getNavigateAction.ts +3 -2
- package/src/server/oneServe.ts +13 -0
- package/src/types.ts +1 -0
- package/src/vite/one.ts +9 -13
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +17 -5
- package/src/vite/types.ts +2 -0
- package/types/cli/build.d.ts.map +1 -1
- package/types/cli/buildPage.d.ts +1 -1
- package/types/cli/buildPage.d.ts.map +1 -1
- package/types/createApp.d.ts.map +1 -1
- package/types/createHandleRequest.d.ts.map +1 -1
- package/types/fork/NavigationContainer.d.ts.map +1 -1
- package/types/fork/createMemoryHistory.d.ts.map +1 -1
- package/types/fork/extractPathFromURL.d.ts.map +1 -1
- package/types/fork/getStateFromPath-mods.d.ts +7 -10
- package/types/fork/getStateFromPath-mods.d.ts.map +1 -1
- package/types/fork/useLinking.d.ts.map +1 -1
- package/types/getReactNavigationConfig.d.ts.map +1 -1
- package/types/hooks.d.ts.map +1 -1
- package/types/router/getRoutes.d.ts.map +1 -1
- package/types/router/matchers.d.ts +10 -3
- package/types/router/matchers.d.ts.map +1 -1
- package/types/router/useViteRoutes.d.ts +2 -0
- package/types/router/useViteRoutes.d.ts.map +1 -1
- package/types/router/utils/getNavigateAction.d.ts.map +1 -1
- package/types/server/oneServe.d.ts.map +1 -1
- package/types/types.d.ts +1 -0
- package/types/types.d.ts.map +1 -1
- package/types/vite/one.d.ts.map +1 -1
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
- package/types/vite/types.d.ts +1 -0
- package/types/vite/types.d.ts.map +1 -1
|
@@ -16,35 +16,44 @@ export type AdditionalRouteConfig = {
|
|
|
16
16
|
hasChildren: boolean
|
|
17
17
|
expandedRouteNames: string[]
|
|
18
18
|
parts: string[]
|
|
19
|
+
staticPartCount: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface UrlWithReactNavigationConcessions {
|
|
23
|
+
path: string
|
|
24
|
+
nonstandardPathname: string
|
|
25
|
+
hash: string
|
|
26
|
+
pathWithoutGroups: string
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
export function getUrlWithReactNavigationConcessions(
|
|
22
30
|
path: string,
|
|
23
31
|
baseUrl: string | undefined = process.env.EXPO_BASE_URL
|
|
24
|
-
) {
|
|
25
|
-
|
|
32
|
+
): UrlWithReactNavigationConcessions {
|
|
33
|
+
const pathWithoutGroups = stripGroupSegmentsFromPath(stripBaseUrl(path, baseUrl))
|
|
34
|
+
|
|
35
|
+
let pathname = ''
|
|
36
|
+
let hash = ''
|
|
26
37
|
try {
|
|
27
|
-
|
|
38
|
+
// NOTE: This used to use a dummy base URL for parsing (phony.example)
|
|
39
|
+
// However, this seems to get flagged since it's preserved 1:1 in the output bytecode by certain scanners
|
|
40
|
+
// Instead, we use an empty `file:` URL. This will still perform `pathname` normalization, search parameter parsing
|
|
41
|
+
// encoding, and all other logic, except the logic that applies to hostnames and protocols, and also not leave a
|
|
42
|
+
// dummy URL in the output bytecode
|
|
43
|
+
const parsed = new URL(path, 'file:')
|
|
44
|
+
pathname = parsed.pathname
|
|
45
|
+
hash = parsed.hash
|
|
28
46
|
} catch {
|
|
29
47
|
// Do nothing with invalid URLs.
|
|
30
|
-
return {
|
|
31
|
-
path,
|
|
32
|
-
cleanUrl: '',
|
|
33
|
-
nonstandardPathname: '',
|
|
34
|
-
url: new URL('https://phony.example'),
|
|
35
|
-
}
|
|
36
48
|
}
|
|
37
49
|
|
|
38
|
-
const pathname = parsed.pathname
|
|
39
50
|
const withoutBaseUrl = stripBaseUrl(pathname, baseUrl)
|
|
40
|
-
const pathWithoutGroups = stripGroupSegmentsFromPath(stripBaseUrl(path, baseUrl))
|
|
41
|
-
|
|
42
|
-
// Make sure there is a trailing slash
|
|
43
51
|
return {
|
|
44
|
-
// The slashes are at the end, not the beginning
|
|
45
52
|
path,
|
|
53
|
+
// Make sure there is a trailing slash
|
|
54
|
+
// The slashes are at the end, not the beginning
|
|
46
55
|
nonstandardPathname: withoutBaseUrl.replace(/^\/+/g, '').replace(/\/+$/g, '') + '/',
|
|
47
|
-
|
|
56
|
+
hash,
|
|
48
57
|
pathWithoutGroups,
|
|
49
58
|
}
|
|
50
59
|
}
|
|
@@ -145,6 +154,13 @@ export function getRouteConfigSorter(previousSegments: string[] = []) {
|
|
|
145
154
|
return 1
|
|
146
155
|
}
|
|
147
156
|
|
|
157
|
+
/*
|
|
158
|
+
* If the routes have any static segments, the one with the most static segments should be higher
|
|
159
|
+
*/
|
|
160
|
+
if (a.staticPartCount !== b.staticPartCount) {
|
|
161
|
+
return b.staticPartCount - a.staticPartCount
|
|
162
|
+
}
|
|
163
|
+
|
|
148
164
|
/*
|
|
149
165
|
* If both are static/dynamic or a layout file, then we check group similarity
|
|
150
166
|
*/
|
|
@@ -312,15 +328,23 @@ export function createConfigItemAdditionalProperties(
|
|
|
312
328
|
): Omit<AdditionalRouteConfig, 'isInitial'> {
|
|
313
329
|
const parts: string[] = []
|
|
314
330
|
let isDynamic = false
|
|
331
|
+
let staticPartCount = 0
|
|
315
332
|
const isIndex = screen === 'index' || screen.endsWith('/index')
|
|
316
333
|
|
|
317
334
|
for (const part of pattern.split('/')) {
|
|
318
335
|
if (part) {
|
|
319
336
|
// If any part is dynamic, then the route is dynamic
|
|
320
|
-
|
|
337
|
+
const isDynamicPart =
|
|
338
|
+
part.startsWith(':') || part.startsWith('*') || part.includes('*not-found')
|
|
339
|
+
|
|
340
|
+
isDynamic ||= isDynamicPart
|
|
321
341
|
|
|
322
342
|
if (!matchGroupName(part)) {
|
|
323
343
|
parts.push(part)
|
|
344
|
+
|
|
345
|
+
if (!isDynamicPart) {
|
|
346
|
+
staticPartCount++
|
|
347
|
+
}
|
|
324
348
|
}
|
|
325
349
|
}
|
|
326
350
|
}
|
|
@@ -330,6 +354,7 @@ export function createConfigItemAdditionalProperties(
|
|
|
330
354
|
|
|
331
355
|
if (isIndex) {
|
|
332
356
|
parts.push('index')
|
|
357
|
+
staticPartCount++
|
|
333
358
|
}
|
|
334
359
|
|
|
335
360
|
return {
|
|
@@ -337,6 +362,7 @@ export function createConfigItemAdditionalProperties(
|
|
|
337
362
|
isIndex,
|
|
338
363
|
hasChildren,
|
|
339
364
|
parts,
|
|
365
|
+
staticPartCount,
|
|
340
366
|
userReadableName: [...routeNames.slice(0, -1), config.path || screen].join('/'),
|
|
341
367
|
expandedRouteNames: routeNames.flatMap((name) => {
|
|
342
368
|
return name.split('/')
|
|
@@ -350,7 +376,7 @@ export function parseQueryParamsExtended(
|
|
|
350
376
|
parseConfig?: Record<string, (value: string) => any>,
|
|
351
377
|
hash?: string
|
|
352
378
|
) {
|
|
353
|
-
const searchParams = new URL(path, '
|
|
379
|
+
const searchParams = new URL(path, 'file:').searchParams
|
|
354
380
|
const params: Record<string, string | string[]> = Object.create(null)
|
|
355
381
|
|
|
356
382
|
if (hash) {
|
|
@@ -189,7 +189,7 @@ export function useLinking(
|
|
|
189
189
|
// If the link were handled, it gets cleared in NavigationContainer
|
|
190
190
|
onUnhandledLinking(extractPathFromURL(prefixes, url))
|
|
191
191
|
const rootState = navigation.getRootState()
|
|
192
|
-
if (state.routes.some((r) => !rootState?.routeNames
|
|
192
|
+
if (state.routes.some((r) => !rootState?.routeNames?.includes(r.name))) {
|
|
193
193
|
return
|
|
194
194
|
}
|
|
195
195
|
|
package/src/fork/useLinking.ts
CHANGED
|
@@ -22,6 +22,7 @@ import isEqual from 'fast-deep-equal'
|
|
|
22
22
|
import * as React from 'react'
|
|
23
23
|
// @modified - start
|
|
24
24
|
// import { ServerContext } from '@react-navigation/web';
|
|
25
|
+
import { rootState as routerRootState } from '../router/router'
|
|
25
26
|
import { ServerLocationContext } from '../router/serverLocationContext'
|
|
26
27
|
import { createMemoryHistory } from './createMemoryHistory'
|
|
27
28
|
import { appendBaseUrl } from './getPathFromState-mods'
|
|
@@ -158,7 +159,7 @@ export function useLinking(
|
|
|
158
159
|
const rootState = navigation?.getRootState()
|
|
159
160
|
// Make sure that the routes in the state exist in the root navigator
|
|
160
161
|
// Otherwise there's an error in the linking configuration
|
|
161
|
-
return state?.routes.some((r) => !rootState?.routeNames
|
|
162
|
+
return state?.routes.some((r) => !rootState?.routeNames?.includes(r.name))
|
|
162
163
|
},
|
|
163
164
|
[ref]
|
|
164
165
|
)
|
|
@@ -180,8 +181,15 @@ export function useLinking(
|
|
|
180
181
|
|
|
181
182
|
const path = location ? location.pathname + location.search : undefined
|
|
182
183
|
|
|
184
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
185
|
+
console.info(`[one] 🔍 getInitialState path=${path}`)
|
|
186
|
+
}
|
|
187
|
+
|
|
183
188
|
if (path) {
|
|
184
189
|
value = getStateFromPathRef.current(path, configRef.current)
|
|
190
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
191
|
+
console.info(`[one] 🔍 getInitialState result:`, JSON.stringify(value, null, 2))
|
|
192
|
+
}
|
|
185
193
|
}
|
|
186
194
|
|
|
187
195
|
// If the link were handled, it gets cleared in NavigationContainer
|
|
@@ -223,6 +231,12 @@ export function useLinking(
|
|
|
223
231
|
|
|
224
232
|
const previousIndex = previousIndexRef.current ?? 0
|
|
225
233
|
|
|
234
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
235
|
+
console.info(
|
|
236
|
+
`[one] 📜 history.listen path=${path} index=${index} prevIndex=${previousIndex}`
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
226
240
|
previousIndexRef.current = index
|
|
227
241
|
pendingPopStatePathRef.current = path
|
|
228
242
|
|
|
@@ -232,12 +246,19 @@ export function useLinking(
|
|
|
232
246
|
const record = history.get(index)
|
|
233
247
|
|
|
234
248
|
if (record?.path === path && record?.state) {
|
|
249
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
250
|
+
console.info(`[one] 📜 history record found, resetRoot to:`, record.state)
|
|
251
|
+
}
|
|
235
252
|
navigation.resetRoot(record.state)
|
|
236
253
|
return
|
|
237
254
|
}
|
|
238
255
|
|
|
239
256
|
const state = getStateFromPathRef.current(path, configRef.current)
|
|
240
257
|
|
|
258
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
259
|
+
console.info(`[one] 📜 getStateFromPath result:`, state)
|
|
260
|
+
}
|
|
261
|
+
|
|
241
262
|
// We should only dispatch an action when going forward
|
|
242
263
|
// Otherwise the action will likely add items to history, which would mess things up
|
|
243
264
|
if (state) {
|
|
@@ -246,6 +267,9 @@ export function useLinking(
|
|
|
246
267
|
// Make sure that the routes in the state exist in the root navigator
|
|
247
268
|
// Otherwise there's an error in the linking configuration
|
|
248
269
|
if (validateRoutesNotExistInRootState(state)) {
|
|
270
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
271
|
+
console.info(`[one] 📜 routes not in root state, skipping`)
|
|
272
|
+
}
|
|
249
273
|
return
|
|
250
274
|
}
|
|
251
275
|
|
|
@@ -256,6 +280,10 @@ export function useLinking(
|
|
|
256
280
|
) {
|
|
257
281
|
const action = getActionFromStateRef.current(state, configRef.current)
|
|
258
282
|
|
|
283
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
284
|
+
console.info(`[one] 📜 dispatching action:`, action)
|
|
285
|
+
}
|
|
286
|
+
|
|
259
287
|
if (action !== undefined) {
|
|
260
288
|
try {
|
|
261
289
|
navigation.dispatch(action)
|
|
@@ -269,13 +297,22 @@ export function useLinking(
|
|
|
269
297
|
)
|
|
270
298
|
}
|
|
271
299
|
} else {
|
|
300
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
301
|
+
console.info(`[one] 📜 no action, resetRoot`)
|
|
302
|
+
}
|
|
272
303
|
navigation.resetRoot(state)
|
|
273
304
|
}
|
|
274
305
|
} else {
|
|
306
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
307
|
+
console.info(`[one] 📜 going back, resetRoot`)
|
|
308
|
+
}
|
|
275
309
|
navigation.resetRoot(state)
|
|
276
310
|
}
|
|
277
311
|
} else {
|
|
278
312
|
// if current path didn't return any state, we should revert to initial state
|
|
313
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
314
|
+
console.info(`[one] 📜 no state for path, resetRoot to undefined`)
|
|
315
|
+
}
|
|
279
316
|
navigation.resetRoot(state)
|
|
280
317
|
}
|
|
281
318
|
})
|
|
@@ -292,6 +329,11 @@ export function useLinking(
|
|
|
292
329
|
): string => {
|
|
293
330
|
let path
|
|
294
331
|
|
|
332
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
333
|
+
console.info(`[one] 📜 getPathForRoute - route:`, route)
|
|
334
|
+
console.info(`[one] 📜 getPathForRoute - state:`, JSON.stringify(state, null, 2))
|
|
335
|
+
}
|
|
336
|
+
|
|
295
337
|
// If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match
|
|
296
338
|
// This makes sure that we preserve the original URL for wildcard routes
|
|
297
339
|
if (route?.path) {
|
|
@@ -315,6 +357,9 @@ export function useLinking(
|
|
|
315
357
|
|
|
316
358
|
if (path == null) {
|
|
317
359
|
path = getPathFromStateRef.current(state, configRef.current)
|
|
360
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
361
|
+
console.info(`[one] 📜 getPathForRoute - computed from state:`, path)
|
|
362
|
+
}
|
|
318
363
|
}
|
|
319
364
|
|
|
320
365
|
// @modified - start: One will handle hashes itself, so these lines are not needed
|
|
@@ -340,14 +385,41 @@ export function useLinking(
|
|
|
340
385
|
if (ref.current) {
|
|
341
386
|
// We need to record the current metadata on the first render if they aren't set
|
|
342
387
|
// This will allow the initial state to be in the history entry
|
|
343
|
-
|
|
388
|
+
// @modified - start: Use routerRootState instead of getRootState() to avoid stale state
|
|
389
|
+
// getRootState() can return incomplete state during initial render before children mount
|
|
390
|
+
// routerRootState is updated via navigation listener callbacks which only fire with complete state
|
|
391
|
+
const refState = ref.current.getRootState()
|
|
392
|
+
const state = (routerRootState || refState) as NavigationState | undefined
|
|
393
|
+
|
|
394
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
395
|
+
console.info(
|
|
396
|
+
`[one] 📜 useEffect initial state check - refState:`,
|
|
397
|
+
JSON.stringify(refState, null, 2)
|
|
398
|
+
)
|
|
399
|
+
console.info(
|
|
400
|
+
`[one] 📜 useEffect initial state check - routerRootState:`,
|
|
401
|
+
JSON.stringify(routerRootState, null, 2)
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
// @modified - end
|
|
344
405
|
|
|
345
406
|
if (state) {
|
|
346
407
|
const route = findFocusedRoute(state)
|
|
408
|
+
|
|
409
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
410
|
+
console.info(`[one] 📜 useEffect focused route:`, route)
|
|
411
|
+
}
|
|
412
|
+
|
|
347
413
|
const path = getPathForRoute(route, state)
|
|
348
414
|
|
|
415
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
416
|
+
console.info(`[one] 📜 initial history.replace - state:`, JSON.stringify(state, null, 2))
|
|
417
|
+
console.info(`[one] 📜 initial history.replace - focusedRoute:`, route)
|
|
418
|
+
console.info(`[one] 📜 initial history.replace - computed path:`, path)
|
|
419
|
+
}
|
|
420
|
+
|
|
349
421
|
if (previousStateRef.current === undefined) {
|
|
350
|
-
previousStateRef.current =
|
|
422
|
+
previousStateRef.current = refState
|
|
351
423
|
}
|
|
352
424
|
|
|
353
425
|
history.replace({ path, state })
|
|
@@ -362,7 +434,10 @@ export function useLinking(
|
|
|
362
434
|
}
|
|
363
435
|
|
|
364
436
|
const previousState = previousStateRef.current
|
|
365
|
-
|
|
437
|
+
// @modified - start: Use routerRootState for path calculation, refState for comparison
|
|
438
|
+
const refState = navigation.getRootState()
|
|
439
|
+
const state = (routerRootState || refState) as NavigationState | undefined
|
|
440
|
+
// @modified - end
|
|
366
441
|
|
|
367
442
|
// root state may not available, for example when root navigators switch inside the container
|
|
368
443
|
if (!state) {
|
|
@@ -373,7 +448,7 @@ export function useLinking(
|
|
|
373
448
|
const route = findFocusedRoute(state)
|
|
374
449
|
const path = getPathForRoute(route, state)
|
|
375
450
|
|
|
376
|
-
previousStateRef.current =
|
|
451
|
+
previousStateRef.current = refState
|
|
377
452
|
pendingPopStatePathRef.current = undefined
|
|
378
453
|
|
|
379
454
|
// To detect the kind of state change, we need to:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { matchDynamicName } from './router/matchers'
|
|
2
2
|
import type { RouteNode } from './router/Route'
|
|
3
3
|
|
|
4
4
|
export type Screen =
|
|
@@ -22,14 +22,12 @@ function convertDynamicRouteToReactNavigation(segment: string): string {
|
|
|
22
22
|
return '*not-found'
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (typeof dynamicName === 'string') {
|
|
32
|
-
return `:${dynamicName}`
|
|
25
|
+
const dynamicMatch = matchDynamicName(segment)
|
|
26
|
+
if (dynamicMatch) {
|
|
27
|
+
if (dynamicMatch.deep) {
|
|
28
|
+
return '*' + dynamicMatch.name
|
|
29
|
+
}
|
|
30
|
+
return `:${dynamicMatch.name}`
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
return segment
|
package/src/hooks.tsx
CHANGED
|
@@ -133,24 +133,26 @@ export function useParams<TParams extends Object = SearchParams>(): Partial<TPar
|
|
|
133
133
|
const params = React.useContext(RouteParamsContext) ?? {}
|
|
134
134
|
|
|
135
135
|
return Object.fromEntries(
|
|
136
|
-
Object.entries(params)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
136
|
+
Object.entries(params)
|
|
137
|
+
.filter(([_, value]) => value !== undefined)
|
|
138
|
+
.map(([key, value]) => {
|
|
139
|
+
if (Array.isArray(value)) {
|
|
140
|
+
return [
|
|
141
|
+
key,
|
|
142
|
+
value.map((v) => {
|
|
143
|
+
try {
|
|
144
|
+
return decodeURIComponent(v)
|
|
145
|
+
} catch {
|
|
146
|
+
return v
|
|
147
|
+
}
|
|
148
|
+
}),
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
return [key, decodeURIComponent(value as string)]
|
|
153
|
+
} catch {
|
|
154
|
+
return [key, value]
|
|
155
|
+
}
|
|
156
|
+
})
|
|
155
157
|
) as TParams
|
|
156
158
|
}
|
package/src/router/getRoutes.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { getPageExport } from '../utils/getPageExport'
|
|
|
3
3
|
import type { One } from '../vite/types'
|
|
4
4
|
import {
|
|
5
5
|
matchArrayGroupName,
|
|
6
|
-
matchDeepDynamicRouteName,
|
|
7
6
|
matchDynamicName,
|
|
8
7
|
matchGroupName,
|
|
9
8
|
removeSupportedExtensions,
|
|
@@ -479,11 +478,9 @@ export function generateDynamic(path: string): DynamicConvention[] | null {
|
|
|
479
478
|
}
|
|
480
479
|
}
|
|
481
480
|
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
if (!dynamicName) return null
|
|
486
|
-
return { name: dynamicName, deep: !!deepDynamicName }
|
|
481
|
+
const dynamicMatch = matchDynamicName(part)
|
|
482
|
+
if (!dynamicMatch) return null
|
|
483
|
+
return { name: dynamicMatch.name, deep: dynamicMatch.deep }
|
|
487
484
|
})
|
|
488
485
|
.filter((part): part is DynamicConvention => !!part)
|
|
489
486
|
|
|
@@ -46,8 +46,8 @@ describe(matchDynamicName, () => {
|
|
|
46
46
|
it(`matches`, () => {
|
|
47
47
|
expect(matchDynamicName('[[...foobar]]')).toEqual(undefined)
|
|
48
48
|
expect(matchDynamicName('[[foobar]]')).toEqual(undefined)
|
|
49
|
-
expect(matchDynamicName('[...foobar]')).toEqual(
|
|
50
|
-
expect(matchDynamicName('[foobar]')).toEqual('foobar')
|
|
49
|
+
expect(matchDynamicName('[...foobar]')).toEqual({ name: 'foobar', deep: true })
|
|
50
|
+
expect(matchDynamicName('[foobar]')).toEqual({ name: 'foobar', deep: false })
|
|
51
51
|
expect(matchDynamicName('foobar')).toEqual(undefined)
|
|
52
52
|
})
|
|
53
53
|
})
|
package/src/router/matchers.ts
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
/** Match `[page]` -> `page` */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/** Match `[page]` -> `page` or `[...page]` -> `page` with deep flag */
|
|
2
|
+
const dynamicNameRe = /^\[([^[\]]+?)\]$/
|
|
3
|
+
|
|
4
|
+
export interface DynamicNameMatch {
|
|
5
|
+
name: string
|
|
6
|
+
deep: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Match `[page]` -> `{ name: 'page', deep: false }` or `[...page]` -> `{ name: 'page', deep: true }` */
|
|
10
|
+
export function matchDynamicName(name: string): DynamicNameMatch | undefined {
|
|
11
|
+
const paramName = name.match(dynamicNameRe)?.[1]
|
|
12
|
+
if (paramName == null) {
|
|
13
|
+
return undefined
|
|
14
|
+
} else if (paramName.startsWith('...')) {
|
|
15
|
+
return { name: paramName.slice(3), deep: true }
|
|
16
|
+
} else {
|
|
17
|
+
return { name: paramName, deep: false }
|
|
18
|
+
}
|
|
6
19
|
}
|
|
7
20
|
|
|
8
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Match `[...page]` -> `page`
|
|
23
|
+
* @deprecated Use matchDynamicName instead which returns {name, deep}
|
|
24
|
+
*/
|
|
9
25
|
export function matchDeepDynamicRouteName(name: string): string | undefined {
|
|
10
26
|
return name.match(/^\[\.\.\.([^/]+?)\]$/)?.[1]
|
|
11
27
|
}
|
package/src/router/router.ts
CHANGED
|
@@ -65,7 +65,7 @@ export function initialize(
|
|
|
65
65
|
throw new Error('No routes found')
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
if (process.env.
|
|
68
|
+
if (process.env.ONE_DEBUG_ROUTER && routeNode) {
|
|
69
69
|
const formatRouteTree = (node: RouteNode, indent = '', isLast = true): string => {
|
|
70
70
|
const prefix = indent + (isLast ? '└─ ' : '├─ ')
|
|
71
71
|
const childIndent = indent + (isLast ? ' ' : '│ ')
|
|
@@ -180,7 +180,7 @@ export function push(url: OneRouter.Href, options?: OneRouter.LinkToOptions) {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
export function dismiss(count?: number) {
|
|
183
|
-
if (process.env.
|
|
183
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
184
184
|
console.info(`[one] 🔙 dismiss${count ? ` (${count})` : ''}`)
|
|
185
185
|
}
|
|
186
186
|
navigationRef?.dispatch(StackActions.pop(count))
|
|
@@ -199,14 +199,14 @@ export function setParams(params: OneRouter.InpurRouteParamsGeneric = {}) {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
export function dismissAll() {
|
|
202
|
-
if (process.env.
|
|
202
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
203
203
|
console.info(`[one] 🔙 dismissAll`)
|
|
204
204
|
}
|
|
205
205
|
navigationRef?.dispatch(StackActions.popToTop())
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
export function goBack() {
|
|
209
|
-
if (process.env.
|
|
209
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
210
210
|
console.info(`[one] 🔙 goBack`)
|
|
211
211
|
}
|
|
212
212
|
assertIsReady(navigationRef)
|
|
@@ -250,7 +250,7 @@ export function updateState(state: OneRouter.ResultState, nextStateParam = state
|
|
|
250
250
|
const nextRouteInfo = getRouteInfo(state)
|
|
251
251
|
|
|
252
252
|
if (!deepEqual(routeInfo, nextRouteInfo)) {
|
|
253
|
-
if (process.env.
|
|
253
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
254
254
|
const from = routeInfo?.pathname || '(initial)'
|
|
255
255
|
const to = nextRouteInfo.pathname
|
|
256
256
|
const params = Object.keys(nextRouteInfo.params || {}).length
|
|
@@ -402,7 +402,7 @@ export function preloadRoute(href: string) {
|
|
|
402
402
|
}
|
|
403
403
|
|
|
404
404
|
export async function linkTo(href: string, event?: string, options?: OneRouter.LinkToOptions) {
|
|
405
|
-
if (process.env.
|
|
405
|
+
if (process.env.ONE_DEBUG_ROUTER) {
|
|
406
406
|
console.info(`[one] 🔗 ${event || 'NAVIGATE'} ${href}`)
|
|
407
407
|
}
|
|
408
408
|
|
|
@@ -26,6 +26,17 @@ export function useViteRoutes(
|
|
|
26
26
|
return context
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// store preloaded modules so resolve() can use them synchronously
|
|
30
|
+
let preloadedModules: Record<string, any> = {}
|
|
31
|
+
|
|
32
|
+
export function registerPreloadedRoute(key: string, module: any): void {
|
|
33
|
+
preloadedModules[key] = module
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getPreloadedModule(key: string): any {
|
|
37
|
+
return preloadedModules[key]
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
export function loadRoutes(
|
|
30
41
|
paths: GlobbedRouteImports,
|
|
31
42
|
routerRoot: string,
|
|
@@ -77,6 +88,14 @@ export function globbedRoutesToRouteContext(
|
|
|
77
88
|
return loadedRoutes[id]
|
|
78
89
|
}
|
|
79
90
|
|
|
91
|
+
// check if this route was preloaded before hydration
|
|
92
|
+
const preloadKey = id.replace('./', `/${routerRoot}/`)
|
|
93
|
+
const preloaded = getPreloadedModule(preloadKey)
|
|
94
|
+
if (preloaded) {
|
|
95
|
+
loadedRoutes[id] = preloaded
|
|
96
|
+
return preloaded
|
|
97
|
+
}
|
|
98
|
+
|
|
80
99
|
if (typeof routesSync[id] !== 'function') {
|
|
81
100
|
return routesSync[id]
|
|
82
101
|
}
|
|
@@ -98,23 +117,6 @@ export function globbedRoutesToRouteContext(
|
|
|
98
117
|
console.error(`Error loading route`, id, err, new Error().stack)
|
|
99
118
|
loadedRoutes[id] = {
|
|
100
119
|
default: () => null,
|
|
101
|
-
// <View
|
|
102
|
-
// style={{
|
|
103
|
-
// position: 'absolute',
|
|
104
|
-
// top: 0,
|
|
105
|
-
// left: 0,
|
|
106
|
-
// right: 0,
|
|
107
|
-
// bottom: 0,
|
|
108
|
-
// alignItems: 'center',
|
|
109
|
-
// justifyContent: 'center',
|
|
110
|
-
// backgroundColor: '#000',
|
|
111
|
-
// gap: 20,
|
|
112
|
-
// }}
|
|
113
|
-
// >
|
|
114
|
-
// <Text style={{ fontSize: 24, color: '#fff' }}>Error loading route</Text>
|
|
115
|
-
// <Text style={{ fontSize: 16, color: '#fff' }}>{id}</Text>
|
|
116
|
-
// <Text style={{ fontSize: 18, color: '#fff', maxWidth: 800 }}>{`${err}`}</Text>
|
|
117
|
-
// </View>
|
|
118
120
|
}
|
|
119
121
|
delete promises[id]
|
|
120
122
|
})
|
|
@@ -39,14 +39,15 @@ export function getNavigateAction(
|
|
|
39
39
|
const childState = actionStateRoute.state
|
|
40
40
|
const nextNavigationState = stateRoute.state
|
|
41
41
|
|
|
42
|
-
const
|
|
42
|
+
const dynamicMatch = matchDynamicName(actionStateRoute.name)
|
|
43
43
|
|
|
44
44
|
const didActionAndCurrentStateDiverge =
|
|
45
45
|
actionStateRoute.name !== stateRoute.name ||
|
|
46
46
|
// !deepEqual(actionStateRoute.params, stateRoute.params) ||
|
|
47
47
|
!childState ||
|
|
48
48
|
!nextNavigationState ||
|
|
49
|
-
(
|
|
49
|
+
(dynamicMatch &&
|
|
50
|
+
actionStateRoute.params?.[dynamicMatch.name] !== stateRoute.params?.[dynamicMatch.name])
|
|
50
51
|
|
|
51
52
|
if (didActionAndCurrentStateDiverge) {
|
|
52
53
|
break
|
package/src/server/oneServe.ts
CHANGED
|
@@ -18,6 +18,8 @@ import { toAbsolute } from '../utils/toAbsolute'
|
|
|
18
18
|
import type { One } from '../vite/types'
|
|
19
19
|
import type { RouteInfoCompiled } from './createRoutesManifest'
|
|
20
20
|
|
|
21
|
+
const debugRouter = process.env.ONE_DEBUG_ROUTER
|
|
22
|
+
|
|
21
23
|
export async function oneServe(oneOptions: One.PluginOptions, buildInfo: One.BuildInfo, app: Hono) {
|
|
22
24
|
const { resolveAPIRoute, resolveLoaderRoute, resolvePageRoute } = await import(
|
|
23
25
|
'../createHandleRequest'
|
|
@@ -36,6 +38,9 @@ export async function oneServe(oneOptions: One.PluginOptions, buildInfo: One.Bui
|
|
|
36
38
|
const paramName = param.substring(1)
|
|
37
39
|
return context.req.param(paramName) || ''
|
|
38
40
|
})
|
|
41
|
+
if (debugRouter) {
|
|
42
|
+
console.info(`[one] ↪ redirect ${context.req.path} → ${destinationUrl}`)
|
|
43
|
+
}
|
|
39
44
|
return context.redirect(destinationUrl, redirect.permanent ? 301 : 302)
|
|
40
45
|
})
|
|
41
46
|
}
|
|
@@ -180,11 +185,19 @@ url: ${url}`)
|
|
|
180
185
|
|
|
181
186
|
switch (route.type) {
|
|
182
187
|
case 'api': {
|
|
188
|
+
if (debugRouter) {
|
|
189
|
+
console.info(`[one] ⚡ ${url.pathname} → matched API route: ${route.page}`)
|
|
190
|
+
}
|
|
183
191
|
return resolveAPIRoute(requestHandlers, request, url, route)
|
|
184
192
|
}
|
|
185
193
|
case 'ssg':
|
|
186
194
|
case 'spa':
|
|
187
195
|
case 'ssr': {
|
|
196
|
+
if (debugRouter) {
|
|
197
|
+
console.info(
|
|
198
|
+
`[one] ⚡ ${url.pathname} → matched page route: ${route.page} (${route.type})`
|
|
199
|
+
)
|
|
200
|
+
}
|
|
188
201
|
return resolvePageRoute(requestHandlers, request, url, route)
|
|
189
202
|
}
|
|
190
203
|
}
|