@@ -22,6 +22,18 @@ import type {
2222 RouteBuilderArguments ,
2323} from '../types/url_builder.ts'
2424
25+ /**
26+ * Options for declarative route redirects
27+ */
28+ type RedirectResponseOptions = {
29+ /** HTTP status code for the redirect response */
30+ status ?: number
31+ /** Whether to forward the incoming request query string */
32+ forwardQueryString ?: boolean
33+ }
34+
35+ type RedirectOptions = URLOptions & RedirectResponseOptions
36+
2537/**
2638 * Brisk routes exposes the API to configure the route handler by chaining
2739 * one of the pre-defined methods.
@@ -102,7 +114,7 @@ export class BriskRoute extends Macroable {
102114 */
103115 redirect < Identifier extends keyof GetRoutesForMethod < RoutesList , 'GET' > & string > (
104116 ...args : RoutesList extends LookupList
105- ? RouteBuilderArguments < Identifier , RoutesList [ 'GET' ] [ Identifier ] , URLOptions >
117+ ? RouteBuilderArguments < Identifier , RoutesList [ 'GET' ] [ Identifier ] , RedirectOptions >
106118 : [ ]
107119 ) : Route {
108120 const [ identifier , params , options ] = args as any [ ]
@@ -112,6 +124,9 @@ export class BriskRoute extends Macroable {
112124 if ( options ?. status ) {
113125 redirector . status ( options . status )
114126 }
127+ if ( options ?. forwardQueryString !== undefined ) {
128+ redirector . withQs ( options . forwardQueryString )
129+ }
115130 return ( redirector . toRoute as any ) ( identifier , params || ctx . params , options )
116131 }
117132
@@ -122,15 +137,18 @@ export class BriskRoute extends Macroable {
122137 /**
123138 * Redirect request to a fixed URL
124139 * @param url - The URL to redirect to
125- * @param options - Optional redirect options including HTTP status code
140+ * @param options - Optional redirect options including HTTP status code and query string forwarding
126141 * @returns The created route instance
127142 */
128- redirectToPath ( url : string , options ?: { status : number } ) : Route {
143+ redirectToPath ( url : string , options ?: RedirectResponseOptions ) : Route {
129144 function redirectsToPath ( ctx : HttpContext ) {
130145 const redirector = ctx . response . redirect ( )
131146 if ( options ?. status ) {
132147 redirector . status ( options . status )
133148 }
149+ if ( options ?. forwardQueryString !== undefined ) {
150+ redirector . withQs ( options . forwardQueryString )
151+ }
134152 return redirector . toPath ( url )
135153 }
136154
0 commit comments