@tanstack/react-router 0.0.1-beta.9 → 1.0.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.
Files changed (229) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/CatchBoundary.js +128 -0
  3. package/build/cjs/CatchBoundary.js.map +1 -0
  4. package/build/cjs/Matches.js +233 -0
  5. package/build/cjs/Matches.js.map +1 -0
  6. package/build/cjs/RouterProvider.js +170 -0
  7. package/build/cjs/RouterProvider.js.map +1 -0
  8. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +2 -22
  9. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  10. package/build/cjs/_virtual/with-selector.development.js +16 -0
  11. package/build/cjs/_virtual/with-selector.development.js.map +1 -0
  12. package/build/cjs/_virtual/with-selector.js +16 -0
  13. package/build/cjs/_virtual/with-selector.js.map +1 -0
  14. package/build/cjs/_virtual/with-selector.production.min.js +16 -0
  15. package/build/cjs/_virtual/with-selector.production.min.js.map +1 -0
  16. package/build/cjs/awaited.js +43 -0
  17. package/build/cjs/awaited.js.map +1 -0
  18. package/build/cjs/build/esm/index.js +79 -0
  19. package/build/cjs/build/esm/index.js.map +1 -0
  20. package/build/cjs/defer.js +37 -0
  21. package/build/cjs/defer.js.map +1 -0
  22. package/build/cjs/fileRoute.js +27 -0
  23. package/build/cjs/fileRoute.js.map +1 -0
  24. package/build/cjs/index.js +130 -0
  25. package/build/cjs/index.js.map +1 -0
  26. package/build/cjs/lazyRouteComponent.js +54 -0
  27. package/build/cjs/lazyRouteComponent.js.map +1 -0
  28. package/build/cjs/link.js +223 -0
  29. package/build/cjs/link.js.map +1 -0
  30. package/build/cjs/node_modules/.pnpm/@tanstack_react-store@0.2.1_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/modern/index.js +47 -0
  31. package/build/cjs/node_modules/.pnpm/@tanstack_react-store@0.2.1_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/modern/index.js.map +1 -0
  32. package/build/cjs/node_modules/.pnpm/@tanstack_store@0.1.3/node_modules/@tanstack/store/build/modern/index.js +70 -0
  33. package/build/cjs/node_modules/.pnpm/@tanstack_store@0.1.3/node_modules/@tanstack/store/build/modern/index.js.map +1 -0
  34. package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +188 -0
  35. package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
  36. package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +39 -0
  37. package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
  38. package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/shim/with-selector.js +26 -0
  39. package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
  40. package/build/cjs/packages/react-router/src/CatchBoundary.js +123 -0
  41. package/build/cjs/packages/react-router/src/CatchBoundary.js.map +1 -0
  42. package/build/cjs/packages/react-router/src/Matches.js +235 -0
  43. package/build/cjs/packages/react-router/src/Matches.js.map +1 -0
  44. package/build/cjs/packages/react-router/src/RouterProvider.js +144 -0
  45. package/build/cjs/packages/react-router/src/RouterProvider.js.map +1 -0
  46. package/build/cjs/packages/react-router/src/awaited.js +43 -0
  47. package/build/cjs/packages/react-router/src/awaited.js.map +1 -0
  48. package/build/cjs/packages/react-router/src/defer.js +37 -0
  49. package/build/cjs/packages/react-router/src/defer.js.map +1 -0
  50. package/build/cjs/packages/react-router/src/fileRoute.js +27 -0
  51. package/build/cjs/packages/react-router/src/fileRoute.js.map +1 -0
  52. package/build/cjs/packages/react-router/src/index.js +61 -0
  53. package/build/cjs/packages/react-router/src/index.js.map +1 -0
  54. package/build/cjs/packages/react-router/src/lazyRouteComponent.js +54 -0
  55. package/build/cjs/packages/react-router/src/lazyRouteComponent.js.map +1 -0
  56. package/build/cjs/packages/react-router/src/link.js +148 -0
  57. package/build/cjs/packages/react-router/src/link.js.map +1 -0
  58. package/build/cjs/packages/react-router/src/path.js +209 -0
  59. package/build/cjs/packages/react-router/src/path.js.map +1 -0
  60. package/build/cjs/packages/react-router/src/qss.js +63 -0
  61. package/build/cjs/packages/react-router/src/qss.js.map +1 -0
  62. package/build/cjs/packages/react-router/src/react.js +634 -0
  63. package/build/cjs/packages/react-router/src/react.js.map +1 -0
  64. package/build/cjs/packages/react-router/src/redirects.js +25 -0
  65. package/build/cjs/packages/react-router/src/redirects.js.map +1 -0
  66. package/build/cjs/packages/react-router/src/route.js +134 -0
  67. package/build/cjs/packages/react-router/src/route.js.map +1 -0
  68. package/build/cjs/packages/react-router/src/router.js +1111 -0
  69. package/build/cjs/packages/react-router/src/router.js.map +1 -0
  70. package/build/cjs/packages/react-router/src/scroll-restoration.js +53 -0
  71. package/build/cjs/packages/react-router/src/scroll-restoration.js.map +1 -0
  72. package/build/cjs/packages/react-router/src/searchParams.js +81 -0
  73. package/build/cjs/packages/react-router/src/searchParams.js.map +1 -0
  74. package/build/cjs/packages/react-router/src/useBlocker.js +61 -0
  75. package/build/cjs/packages/react-router/src/useBlocker.js.map +1 -0
  76. package/build/cjs/packages/react-router/src/useNavigate.js +75 -0
  77. package/build/cjs/packages/react-router/src/useNavigate.js.map +1 -0
  78. package/build/cjs/packages/react-router/src/useParams.js +26 -0
  79. package/build/cjs/packages/react-router/src/useParams.js.map +1 -0
  80. package/build/cjs/packages/react-router/src/useSearch.js +25 -0
  81. package/build/cjs/packages/react-router/src/useSearch.js.map +1 -0
  82. package/build/cjs/packages/react-router/src/utils.js +239 -0
  83. package/build/cjs/packages/react-router/src/utils.js.map +1 -0
  84. package/build/cjs/path.js +214 -0
  85. package/build/cjs/path.js.map +1 -0
  86. package/build/cjs/qss.js +63 -0
  87. package/build/cjs/qss.js.map +1 -0
  88. package/build/cjs/react/CatchBoundary.js +123 -0
  89. package/build/cjs/react/CatchBoundary.js.map +1 -0
  90. package/build/cjs/react/awaited.js +43 -0
  91. package/build/cjs/react/awaited.js.map +1 -0
  92. package/build/cjs/react/defer.js +37 -0
  93. package/build/cjs/react/defer.js.map +1 -0
  94. package/build/cjs/react.js +650 -0
  95. package/build/cjs/react.js.map +1 -0
  96. package/build/cjs/redirects.js +28 -0
  97. package/build/cjs/redirects.js.map +1 -0
  98. package/build/cjs/route.js +191 -0
  99. package/build/cjs/route.js.map +1 -0
  100. package/build/cjs/router.js +1085 -0
  101. package/build/cjs/router.js.map +1 -0
  102. package/build/cjs/routerConfig.js +209 -0
  103. package/build/cjs/routerConfig.js.map +1 -0
  104. package/build/cjs/scroll-restoration.js +202 -0
  105. package/build/cjs/scroll-restoration.js.map +1 -0
  106. package/build/cjs/searchParams.js +81 -0
  107. package/build/cjs/searchParams.js.map +1 -0
  108. package/build/cjs/src/CatchBoundary.js +126 -0
  109. package/build/cjs/src/CatchBoundary.js.map +1 -0
  110. package/build/cjs/src/Matches.js +235 -0
  111. package/build/cjs/src/Matches.js.map +1 -0
  112. package/build/cjs/src/RouterProvider.js +1051 -0
  113. package/build/cjs/src/RouterProvider.js.map +1 -0
  114. package/build/cjs/src/awaited.js +45 -0
  115. package/build/cjs/src/awaited.js.map +1 -0
  116. package/build/cjs/src/defer.js +39 -0
  117. package/build/cjs/src/defer.js.map +1 -0
  118. package/build/cjs/src/fileRoute.js +29 -0
  119. package/build/cjs/src/fileRoute.js.map +1 -0
  120. package/build/cjs/src/index.js +134 -0
  121. package/build/cjs/src/index.js.map +1 -0
  122. package/build/cjs/src/lazyRouteComponent.js +57 -0
  123. package/build/cjs/src/lazyRouteComponent.js.map +1 -0
  124. package/build/cjs/src/link.js +151 -0
  125. package/build/cjs/src/link.js.map +1 -0
  126. package/build/cjs/src/path.js +211 -0
  127. package/build/cjs/src/path.js.map +1 -0
  128. package/build/cjs/src/qss.js +65 -0
  129. package/build/cjs/src/qss.js.map +1 -0
  130. package/build/cjs/src/redirects.js +27 -0
  131. package/build/cjs/src/redirects.js.map +1 -0
  132. package/build/cjs/src/route.js +139 -0
  133. package/build/cjs/src/route.js.map +1 -0
  134. package/build/cjs/src/router.js +203 -0
  135. package/build/cjs/src/router.js.map +1 -0
  136. package/build/cjs/src/scroll-restoration.js +186 -0
  137. package/build/cjs/src/scroll-restoration.js.map +1 -0
  138. package/build/cjs/src/searchParams.js +83 -0
  139. package/build/cjs/src/searchParams.js.map +1 -0
  140. package/build/cjs/src/useBlocker.js +64 -0
  141. package/build/cjs/src/useBlocker.js.map +1 -0
  142. package/build/cjs/src/useNavigate.js +78 -0
  143. package/build/cjs/src/useNavigate.js.map +1 -0
  144. package/build/cjs/src/useParams.js +28 -0
  145. package/build/cjs/src/useParams.js.map +1 -0
  146. package/build/cjs/src/useSearch.js +27 -0
  147. package/build/cjs/src/useSearch.js.map +1 -0
  148. package/build/cjs/src/utils.js +230 -0
  149. package/build/cjs/src/utils.js.map +1 -0
  150. package/build/cjs/useBlocker.js +55 -0
  151. package/build/cjs/useBlocker.js.map +1 -0
  152. package/build/cjs/useNavigate.js +86 -0
  153. package/build/cjs/useNavigate.js.map +1 -0
  154. package/build/cjs/useParams.js +26 -0
  155. package/build/cjs/useParams.js.map +1 -0
  156. package/build/cjs/useSearch.js +25 -0
  157. package/build/cjs/useSearch.js.map +1 -0
  158. package/build/cjs/useStore.js +99 -0
  159. package/build/cjs/useStore.js.map +1 -0
  160. package/build/cjs/utils.js +241 -0
  161. package/build/cjs/utils.js.map +1 -0
  162. package/build/esm/index.js +2300 -2534
  163. package/build/esm/index.js.map +1 -1
  164. package/build/stats-html.html +3498 -2694
  165. package/build/stats-react.json +1204 -44
  166. package/build/types/CatchBoundary.d.ts +36 -0
  167. package/build/types/Matches.d.ts +64 -0
  168. package/build/types/RouteMatch.d.ts +23 -0
  169. package/build/types/RouterProvider.d.ts +35 -0
  170. package/build/types/awaited.d.ts +9 -0
  171. package/build/types/defer.d.ts +19 -0
  172. package/build/types/fileRoute.d.ts +38 -0
  173. package/build/types/history.d.ts +7 -0
  174. package/build/types/index.d.ts +919 -58
  175. package/build/types/injectHtml.d.ts +0 -0
  176. package/build/types/lazyRouteComponent.d.ts +2 -0
  177. package/build/types/link.d.ts +93 -0
  178. package/build/types/location.d.ts +12 -0
  179. package/build/types/path.d.ts +17 -0
  180. package/build/types/qss.d.ts +2 -0
  181. package/build/types/react/CatchBoundary.d.ts +33 -0
  182. package/build/types/react/awaited.d.ts +9 -0
  183. package/build/types/react/defer.d.ts +19 -0
  184. package/build/types/react.d.ts +141 -0
  185. package/build/types/redirects.d.ts +11 -0
  186. package/build/types/route.d.ts +283 -0
  187. package/build/types/routeInfo.d.ts +31 -0
  188. package/build/types/router.d.ts +186 -0
  189. package/build/types/scroll-restoration.d.ts +18 -0
  190. package/build/types/searchParams.d.ts +7 -0
  191. package/build/types/useBlocker.d.ts +9 -0
  192. package/build/types/useNavigate.d.ts +19 -0
  193. package/build/types/useParams.d.ts +7 -0
  194. package/build/types/useSearch.d.ts +7 -0
  195. package/build/types/useStore.d.ts +12 -0
  196. package/build/types/utils.d.ts +69 -0
  197. package/build/umd/index.development.js +2897 -2493
  198. package/build/umd/index.development.js.map +1 -1
  199. package/build/umd/index.production.js +4 -4
  200. package/build/umd/index.production.js.map +1 -1
  201. package/package.json +12 -10
  202. package/src/CatchBoundary.tsx +101 -0
  203. package/src/Matches.tsx +423 -0
  204. package/src/RouterProvider.tsx +252 -0
  205. package/src/awaited.tsx +40 -0
  206. package/src/defer.ts +55 -0
  207. package/src/fileRoute.ts +152 -0
  208. package/src/history.ts +8 -0
  209. package/src/index.tsx +28 -619
  210. package/src/lazyRouteComponent.tsx +33 -0
  211. package/src/link.tsx +603 -0
  212. package/src/location.ts +13 -0
  213. package/src/path.ts +261 -0
  214. package/src/qss.ts +53 -0
  215. package/src/redirects.ts +39 -0
  216. package/src/route.ts +882 -0
  217. package/src/routeInfo.ts +84 -0
  218. package/src/router.ts +1671 -0
  219. package/src/scroll-restoration.tsx +230 -0
  220. package/src/searchParams.ts +79 -0
  221. package/src/useBlocker.tsx +27 -0
  222. package/src/useNavigate.tsx +111 -0
  223. package/src/useParams.tsx +25 -0
  224. package/src/useSearch.tsx +25 -0
  225. package/src/utils.ts +360 -0
  226. package/build/cjs/react-router/src/index.js +0 -458
  227. package/build/cjs/react-router/src/index.js.map +0 -1
  228. package/build/cjs/router-core/build/esm/index.js +0 -2524
  229. package/build/cjs/router-core/build/esm/index.js.map +0 -1
package/src/path.ts ADDED
@@ -0,0 +1,261 @@
1
+ import { MatchLocation } from './RouterProvider'
2
+ import { AnyPathParams } from './route'
3
+ import { last } from './utils'
4
+
5
+ export interface Segment {
6
+ type: 'pathname' | 'param' | 'wildcard'
7
+ value: string
8
+ }
9
+
10
+ export function joinPaths(paths: (string | undefined)[]) {
11
+ return cleanPath(paths.filter(Boolean).join('/'))
12
+ }
13
+
14
+ export function cleanPath(path: string) {
15
+ // remove double slashes
16
+ return path.replace(/\/{2,}/g, '/')
17
+ }
18
+
19
+ export function trimPathLeft(path: string) {
20
+ return path === '/' ? path : path.replace(/^\/{1,}/, '')
21
+ }
22
+
23
+ export function trimPathRight(path: string) {
24
+ return path === '/' ? path : path.replace(/\/{1,}$/, '')
25
+ }
26
+
27
+ export function trimPath(path: string) {
28
+ return trimPathRight(trimPathLeft(path))
29
+ }
30
+
31
+ export function resolvePath(basepath: string, base: string, to: string) {
32
+ base = base.replace(new RegExp(`^${basepath}`), '/')
33
+ to = to.replace(new RegExp(`^${basepath}`), '/')
34
+
35
+ let baseSegments = parsePathname(base)
36
+ const toSegments = parsePathname(to)
37
+
38
+ toSegments.forEach((toSegment, index) => {
39
+ if (toSegment.value === '/') {
40
+ if (!index) {
41
+ // Leading slash
42
+ baseSegments = [toSegment]
43
+ } else if (index === toSegments.length - 1) {
44
+ // Trailing Slash
45
+ baseSegments.push(toSegment)
46
+ } else {
47
+ // ignore inter-slashes
48
+ }
49
+ } else if (toSegment.value === '..') {
50
+ // Extra trailing slash? pop it off
51
+ if (baseSegments.length > 1 && last(baseSegments)?.value === '/') {
52
+ baseSegments.pop()
53
+ }
54
+ baseSegments.pop()
55
+ } else if (toSegment.value === '.') {
56
+ return
57
+ } else {
58
+ baseSegments.push(toSegment)
59
+ }
60
+ })
61
+
62
+ const joined = joinPaths([basepath, ...baseSegments.map((d) => d.value)])
63
+
64
+ return cleanPath(joined)
65
+ }
66
+
67
+ export function parsePathname(pathname?: string): Segment[] {
68
+ if (!pathname) {
69
+ return []
70
+ }
71
+
72
+ pathname = cleanPath(pathname)
73
+
74
+ const segments: Segment[] = []
75
+
76
+ if (pathname.slice(0, 1) === '/') {
77
+ pathname = pathname.substring(1)
78
+ segments.push({
79
+ type: 'pathname',
80
+ value: '/',
81
+ })
82
+ }
83
+
84
+ if (!pathname) {
85
+ return segments
86
+ }
87
+
88
+ // Remove empty segments and '.' segments
89
+ const split = pathname.split('/').filter(Boolean)
90
+
91
+ segments.push(
92
+ ...split.map((part): Segment => {
93
+ if (part === '$' || part === '*') {
94
+ return {
95
+ type: 'wildcard',
96
+ value: part,
97
+ }
98
+ }
99
+
100
+ if (part.charAt(0) === '$') {
101
+ return {
102
+ type: 'param',
103
+ value: part,
104
+ }
105
+ }
106
+
107
+ return {
108
+ type: 'pathname',
109
+ value: part,
110
+ }
111
+ }),
112
+ )
113
+
114
+ if (pathname.slice(-1) === '/') {
115
+ pathname = pathname.substring(1)
116
+ segments.push({
117
+ type: 'pathname',
118
+ value: '/',
119
+ })
120
+ }
121
+
122
+ return segments
123
+ }
124
+
125
+ export function interpolatePath(
126
+ path: string | undefined,
127
+ params: any,
128
+ leaveWildcards: boolean = false,
129
+ ) {
130
+ const interpolatedPathSegments = parsePathname(path)
131
+
132
+ return joinPaths(
133
+ interpolatedPathSegments.map((segment) => {
134
+ if (segment.type === 'wildcard') {
135
+ const value = params[segment.value]
136
+ if (leaveWildcards) return `${segment.value}${value ?? ''}`
137
+ return value
138
+ }
139
+
140
+ if (segment.type === 'param') {
141
+ return params![segment.value.substring(1)] ?? 'undefined'
142
+ }
143
+
144
+ return segment.value
145
+ }),
146
+ )
147
+ }
148
+
149
+ export function matchPathname(
150
+ basepath: string,
151
+ currentPathname: string,
152
+ matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>,
153
+ ): AnyPathParams | undefined {
154
+ const pathParams = matchByPath(basepath, currentPathname, matchLocation)
155
+ // const searchMatched = matchBySearch(location.search, matchLocation)
156
+
157
+ if (matchLocation.to && !pathParams) {
158
+ return
159
+ }
160
+
161
+ return pathParams ?? {}
162
+ }
163
+
164
+ export function removeBasepath(basepath: string, pathname: string) {
165
+ return basepath != '/' ? pathname.substring(basepath.length) : pathname
166
+ }
167
+
168
+ export function matchByPath(
169
+ basepath: string,
170
+ from: string,
171
+ matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>,
172
+ ): Record<string, string> | undefined {
173
+ // Remove the base path from the pathname
174
+ from = removeBasepath(basepath, from)
175
+ // Default to to $ (wildcard)
176
+ const to = `${matchLocation.to ?? '$'}`
177
+ // Parse the from and to
178
+ const baseSegments = parsePathname(from)
179
+ const routeSegments = parsePathname(to)
180
+
181
+ if (!from.startsWith('/')) {
182
+ baseSegments.unshift({
183
+ type: 'pathname',
184
+ value: '/',
185
+ })
186
+ }
187
+
188
+ if (!to.startsWith('/')) {
189
+ routeSegments.unshift({
190
+ type: 'pathname',
191
+ value: '/',
192
+ })
193
+ }
194
+
195
+ const params: Record<string, string> = {}
196
+
197
+ let isMatch = (() => {
198
+ for (
199
+ let i = 0;
200
+ i < Math.max(baseSegments.length, routeSegments.length);
201
+ i++
202
+ ) {
203
+ const baseSegment = baseSegments[i]
204
+ const routeSegment = routeSegments[i]
205
+
206
+ const isLastBaseSegment = i >= baseSegments.length - 1
207
+ const isLastRouteSegment = i >= routeSegments.length - 1
208
+
209
+ if (routeSegment) {
210
+ if (routeSegment.type === 'wildcard') {
211
+ if (baseSegment?.value) {
212
+ params['*'] = joinPaths(baseSegments.slice(i).map((d) => d.value))
213
+ return true
214
+ }
215
+ return false
216
+ }
217
+
218
+ if (routeSegment.type === 'pathname') {
219
+ if (routeSegment.value === '/' && !baseSegment?.value) {
220
+ return true
221
+ }
222
+
223
+ if (baseSegment) {
224
+ if (matchLocation.caseSensitive) {
225
+ if (routeSegment.value !== baseSegment.value) {
226
+ return false
227
+ }
228
+ } else if (
229
+ routeSegment.value.toLowerCase() !==
230
+ baseSegment.value.toLowerCase()
231
+ ) {
232
+ return false
233
+ }
234
+ }
235
+ }
236
+
237
+ if (!baseSegment) {
238
+ return false
239
+ }
240
+
241
+ if (routeSegment.type === 'param') {
242
+ if (baseSegment?.value === '/') {
243
+ return false
244
+ }
245
+ if (baseSegment.value.charAt(0) !== '$') {
246
+ params[routeSegment.value.substring(1)] = baseSegment.value
247
+ }
248
+ }
249
+ }
250
+
251
+ if (!isLastBaseSegment && isLastRouteSegment) {
252
+ params['**'] = joinPaths(baseSegments.slice(i + 1).map((d) => d.value))
253
+ return !!matchLocation.fuzzy && routeSegment?.value !== '/'
254
+ }
255
+ }
256
+
257
+ return true
258
+ })()
259
+
260
+ return isMatch ? (params as Record<string, string>) : undefined
261
+ }
package/src/qss.ts ADDED
@@ -0,0 +1,53 @@
1
+ // @ts-nocheck
2
+
3
+ // qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
4
+
5
+ export function encode(obj, pfx?: string) {
6
+ var k,
7
+ i,
8
+ tmp,
9
+ str = ''
10
+
11
+ for (k in obj) {
12
+ if ((tmp = obj[k]) !== void 0) {
13
+ if (Array.isArray(tmp)) {
14
+ for (i = 0; i < tmp.length; i++) {
15
+ str && (str += '&')
16
+ str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])
17
+ }
18
+ } else {
19
+ str && (str += '&')
20
+ str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)
21
+ }
22
+ }
23
+ }
24
+
25
+ return (pfx || '') + str
26
+ }
27
+
28
+ function toValue(mix) {
29
+ if (!mix) return ''
30
+ var str = decodeURIComponent(mix)
31
+ if (str === 'false') return false
32
+ if (str === 'true') return true
33
+ return +str * 0 === 0 && +str + '' === str ? +str : str
34
+ }
35
+
36
+ export function decode(str) {
37
+ var tmp,
38
+ k,
39
+ out = {},
40
+ arr = str.split('&')
41
+
42
+ while ((tmp = arr.shift())) {
43
+ tmp = tmp.split('=')
44
+ k = tmp.shift()
45
+ if (out[k] !== void 0) {
46
+ out[k] = [].concat(out[k], toValue(tmp.shift()))
47
+ } else {
48
+ out[k] = toValue(tmp.shift())
49
+ }
50
+ }
51
+
52
+ return out
53
+ }
@@ -0,0 +1,39 @@
1
+ import { NavigateOptions } from './link'
2
+ import { AnyRoute } from './route'
3
+ import { RoutePaths } from './routeInfo'
4
+ import { RegisteredRouter } from './router'
5
+
6
+ // Detect if we're in the DOM
7
+
8
+ export type AnyRedirect = Redirect<any, any, any, any, any>
9
+
10
+ export type Redirect<
11
+ TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
12
+ TFrom extends RoutePaths<TRouteTree> = '/',
13
+ TTo extends string = '',
14
+ TMaskFrom extends RoutePaths<TRouteTree> = TFrom,
15
+ TMaskTo extends string = '',
16
+ > = {
17
+ code?: number
18
+ throw?: any
19
+ } & NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>
20
+
21
+ export function redirect<
22
+ TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
23
+ TFrom extends RoutePaths<TRouteTree> = '/',
24
+ TTo extends string = '',
25
+ TMaskFrom extends RoutePaths<TRouteTree> = TFrom,
26
+ TMaskTo extends string = '',
27
+ >(
28
+ opts: Redirect<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,
29
+ ): Redirect<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> {
30
+ ;(opts as any).isRedirect = true
31
+ if (opts.throw) {
32
+ throw opts
33
+ }
34
+ return opts
35
+ }
36
+
37
+ export function isRedirect(obj: any): obj is AnyRedirect {
38
+ return !!obj?.isRedirect
39
+ }