Like with all question, the answer is: it depends.
The quickest way is to end your route definitions with a catch-all: "(:any)" => ...". And either route that to a 404 controller of some sort, or assign a closure that throws a HttpNotFoundException.
You can also catch it in the controller, either in a specific method, or using the router() method, by checking if Request::active() == Request::main(). If so, it's a URI request. If not, it's an HMVC call.