From a395b7ae17e2b2beeb8005f73fb447c3dc853a5a Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Wed, 5 Feb 2025 11:31:31 -0500 Subject: [PATCH] Update SegmentRouterTrait.php --- src/SegmentRouterTrait.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/SegmentRouterTrait.php b/src/SegmentRouterTrait.php index 11ea2f3..a27490d 100644 --- a/src/SegmentRouterTrait.php +++ b/src/SegmentRouterTrait.php @@ -63,6 +63,10 @@ trait SegmentRouterTrait // node is a reference to our current location in the node tree $node = $routes; + if ($uri === '/' && isset($node[$method]) && array_key_exists($method, $node)) { + return ['code' => 200, 'handler' => $node[$method], 'params' => null]; + } + // params will hold any dynamic segments we find $params = []; foreach (explode('/', trim($uri, '/')) as $segment) { @@ -82,9 +86,7 @@ trait SegmentRouterTrait } // if we found a handler for the method, return it and any params. if not, return a 405 - return isset($node[$method]) - ? ['code' => 200, 'handler' => $node[$method], 'params' => $params] - : ['code' => 404, 'handler' => null, 'params' => []]; + return ['code' => 200, 'handler' => $node[$method], 'params' => $params]; } /**