Closure routes are those routes in which we don’t bind controller and it’s method for url function. Instead we process route function by using closure callback function.
$route->get("<route>", function(){ ... });
When we define route closures, it means we are going to call request function in route file itself.
//... // route with static message $routes->get("contact-us", function () { echo "<h1>Welcome to Online Web Tutor</h1>"; }); // route with view file $routes->get("about-us", function () { return view("about-us"); // /app/Views/about-us.php }); // route with parameter $routes->get("services/(:num)", function ($id) { echo "ID: ".$id; }); //...
- /contact-us, /about-us etc route is handled by callback function.
Inside all above route, we didn’t map any controller and method. You can use any method type.