@@ -433,29 +433,22 @@ Routing <- R6::R6Class(
433
433
# we reorder the routes before launching the app
434
434
# we make sure the longest patterns are checked first
435
435
# this makes sure /:id/x matches BEFORE /:id does
436
- # howerver we also want to try to match extact paths
437
- # BEFORE dynamic once
436
+ # however we also want to try to match exact paths
437
+ # BEFORE dynamic ones
438
438
# e.g. /hello should be matched before /:id
439
- # TODO https://github.com/devOpifex/ambiorix/issues/47
440
439
reorder_routes = function () {
441
440
indices <- seq_along(private $ .routes )
442
- pats <- lapply(private $ .routes , \ (route ) {
441
+ paths <- lapply(private $ .routes , function (route ) {
443
442
data.frame (
444
- pattern = route $ route $ pattern ,
443
+ nchar = nchar( route $ route $ path ) ,
445
444
dynamic = route $ route $ dynamic
446
445
)
447
446
})
448
- df <- do.call(rbind , pats )
447
+ df <- do.call(rbind , paths )
449
448
df $ order <- seq_len(nrow(df ))
450
- df $ nchar <- nchar(df $ pattern )
451
449
df <- df [order(df $ dynamic , - df $ nchar ), ]
452
450
453
- new_routes <- as.list(c(seq_len(nrow(df ))))
454
- for (i in seq_len(nrow(df ))) {
455
- new_routes [[i ]] <- private $ .routes [[df $ order [i ]]]
456
- }
457
-
458
- private $ .routes <- rev(new_routes )
451
+ private $ .routes <- private $ .routes [df $ order ]
459
452
},
460
453
.call = function (req ){
461
454
0 commit comments