@@ -12,7 +12,6 @@ type ActionPath = string
12
12
13
13
export class Router implements RouterInterface {
14
14
private routes : Route [ ] = [ ]
15
- private groupPrefix = ''
16
15
private path = ''
17
16
18
17
private addRoute (
@@ -168,8 +167,6 @@ export class Router implements RouterInterface {
168
167
169
168
let cb : ( ) => void
170
169
171
- this . prepareGroupPrefix ( options )
172
-
173
170
if ( typeof options === 'function' ) {
174
171
cb = options
175
172
options = { }
@@ -191,21 +188,61 @@ export class Router implements RouterInterface {
191
188
// Execute the callback. This will add routes to the new this.routes array
192
189
cb ( )
193
190
194
- // For each route added by the callback, adjust the URI and add to the original routes array
195
- this . routes . forEach ( ( r ) => {
196
- if ( middleware . length )
197
- r . middleware = middleware
191
+ if ( typeof options === 'object' ) {
192
+ this . routes . forEach ( ( r ) => {
193
+ // Add middleware if any
194
+ if ( middleware . length )
195
+ r . middleware = middleware
196
+
197
+ // Add the prefix to the route path
198
+
199
+ if ( options . prefix ) {
200
+ r . path = `${ options . prefix } /${ r . uri } `
201
+ r . uri = `${ options . prefix } /${ r . uri } `
202
+ r . url = `${ options . prefix } /${ r . uri } `
203
+ }
204
+
205
+ // Push the modified route to the original routes array
206
+ originalRoutes . push ( r )
207
+
208
+ return this
209
+ } )
210
+ }
198
211
199
- originalRoutes . push ( r )
200
- return this
201
- } )
212
+ // this.prepareGroupPrefix(this.routes, options, middleware)
202
213
203
214
// Restore the original routes array.
204
215
this . routes = originalRoutes
205
216
206
217
return this
207
218
}
208
219
220
+ // private prepareGroupPrefix(routes: Route[], options: string | RouteGroupOptions, middleware: string | string[]): void {
221
+ // if (typeof options !== 'string') {
222
+ // routes.forEach((r) => {
223
+ // // Add middleware if any
224
+ // if (middleware.length)
225
+ // r.middleware = middleware
226
+
227
+ // // Add the prefix to the route path
228
+ // if (options.prefix) {
229
+ // r.path = `/${options.prefix}${r.path}`
230
+ // }
231
+
232
+ // // Push the modified route to the original routes array
233
+ // originalRoutes.push(r)
234
+ // return this
235
+ // })
236
+
237
+ // return
238
+ // }
239
+
240
+ // if (typeof options === 'string') {
241
+
242
+ // return
243
+ // }
244
+ // }
245
+
209
246
public name ( name : string ) : this {
210
247
this . routes [ this . routes . length - 1 ] . name = name
211
248
@@ -231,33 +268,6 @@ export class Router implements RouterInterface {
231
268
return this . routes
232
269
}
233
270
234
- private setGroupPrefix ( prefix : string , options : RouteGroupOptions = { } ) {
235
- if ( prefix !== '' ) {
236
- prefix = `/${ this . groupPrefix } /${ prefix } ` . replace ( / \/ \/ / g, '/' ) // remove double slashes in case there are any
237
- this . groupPrefix = prefix
238
- return
239
- }
240
-
241
- // Ensure options is always treated as an object, even if it's undefined or a function
242
- const effectiveOptions = typeof options === 'object' ? options : { }
243
-
244
- this . groupPrefix = effectiveOptions . prefix ?? prefix ?? ''
245
- }
246
-
247
- private prepareGroupPrefix ( options : string | RouteGroupOptions ) : void {
248
- if ( this . groupPrefix !== '' && typeof options !== 'string' ) {
249
- this . setGroupPrefix ( this . groupPrefix , options )
250
- return
251
- }
252
-
253
- if ( typeof options === 'string' ) {
254
- this . setGroupPrefix ( options )
255
- return
256
- }
257
-
258
- this . setGroupPrefix ( '' , options )
259
- }
260
-
261
271
public async resolveCallback ( callback : Route [ 'callback' ] ) : Promise < Route [ 'callback' ] > {
262
272
if ( callback instanceof Promise ) {
263
273
const actionModule = await callback
@@ -377,8 +387,7 @@ export class Router implements RouterInterface {
377
387
if ( path . startsWith ( '/' ) )
378
388
path = path . slice ( 1 )
379
389
380
- path = `${ this . groupPrefix } /${ path } `
381
-
390
+ path = `/${ path } `
382
391
// if path ends in "/", then remove it
383
392
// e.g. triggered when route is "/"
384
393
return path . endsWith ( '/' ) ? path . slice ( 0 , - 1 ) : path
0 commit comments