Router::wasMatched() always returns true

Hey people! I must've misunderstood something, but I've added the following for my routing:

    $di->set('router', function() {
        new Router();
        $router->setDefaultNamespace('\Customer\Controllers');

        // Add index route.
        $router->add(
            "/",
            array(
                "controller" => "index",
                "action" => "index"
            )
        );

        // Set up error routing.
        $router->notFound(
            array(
                "controller" => "Error",
                "action" => "notFound"
            )
        );

        $router->handle();
        return $router;
    });

And when I request /ndosnd, the Router::wasMatched() returns true with Router::getMatches() being the following:

array (size=2)
  0 => string '/ndosnd' (length=5)
  1 => string 'ndosnd' (length=4)

I expected this match to fail and go to the ErrorController::notFoundAction(). What's going on?

Thanks for your time.

// dimhoLt

It might be that since you set up a notFound route, it is considering that a match.



85.3k
edited Aug '14

Default routes match almost every possible URI passed to the application, you can see default routes here: