diff --git a/src/SegmentRouter.php b/src/SegmentRouter.php index a149d33..5247c68 100644 --- a/src/SegmentRouter.php +++ b/src/SegmentRouter.php @@ -70,9 +70,6 @@ class SegmentRouter implements RouterInterface // node is a reference to our current location in the node tree $node = $this->routes; - // params will hold any dynamic segments we find - $params = []; - // if the URI is just a slash, we can return the handler for the root node if ($uri === '/') { return isset($node[$method]) @@ -80,6 +77,9 @@ class SegmentRouter implements RouterInterface : ['code' => 405, 'handler' => null, 'params' => null]; } + // params will hold any dynamic segments we find + $params = []; + // We'll split up the URI into segments and traverse the node tree foreach (explode('/', trim($uri, '/')) as $segment) { // if there is a node for this segment, move to it