File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -134,9 +134,27 @@ export interface RootBuildConfig {
134
134
}
135
135
136
136
export interface RootRedirectConfig {
137
+ /**
138
+ * The source path to redirect. Accepts placeholders in the format
139
+ * `[key]` or `[...key]`. Use `[key]` for single segments and
140
+ * `[...key]` for multi-segment wildcards.
141
+ * @example "/old-path/[id]" or "/old-path/[...wildcard]"
142
+ */
137
143
source : string ;
144
+
145
+ /**
146
+ * The destination to redirect to. Placeholders from the source can
147
+ * optionally be inserted into the destination using the same
148
+ * placeholder format.
149
+ * @example "/new-path/[id]" or "/new-path/[...wildcard]"
150
+ */
138
151
destination : string ;
139
- type ?: number ;
152
+
153
+ /**
154
+ * The redirect type (`301` = permanent, `302` = temporary). If unspecified,
155
+ * defaults to `302` (temporary).
156
+ */
157
+ type ?: 301 | 302 ;
140
158
}
141
159
142
160
export interface RootHeaderConfig {
@@ -218,7 +236,22 @@ export interface RootServerConfig {
218
236
sessionCookieSecret ?: string | string [ ] ;
219
237
220
238
/**
221
- * List of redirects.
239
+ * List of redirects. Supports optional wildcards.
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * redirects: [
244
+ * {
245
+ * source: '/old-path/[id]',
246
+ * destination: '/new-path/[id]',
247
+ * type: 301,
248
+ * },
249
+ * {
250
+ * source: '/old-path/[...wildcard]',
251
+ * destination: '/new-path/[...wildcard]',
252
+ * },
253
+ * ]
254
+ * ```
222
255
*/
223
256
redirects ?: RootRedirectConfig [ ] ;
224
257
Original file line number Diff line number Diff line change @@ -44,6 +44,13 @@ function verifyRedirectConfig(redirect: RootRedirectConfig) {
44
44
return true ;
45
45
}
46
46
47
+ /**
48
+ * Replaces placeholders in a URL path format string with actual values.
49
+ *
50
+ * @param urlPathFormat The URL path format string containing parameter placeholders in the format `[key]` or `[...key]`.
51
+ * @param params A map of parameter names to their corresponding values.
52
+ * @returns The URL path with all parameter placeholders replaced by their corresponding values.
53
+ */
47
54
function replaceParams ( urlPathFormat : string , params : Record < string , string > ) {
48
55
const urlPath = urlPathFormat . replaceAll (
49
56
/ \[ \[ ? ( \. \. \. ) ? ( [ \w \- _ ] * ) \] ? \] / g,
You can’t perform that action at this time.
0 commit comments