Posts Learn Components new Snippets new Categories Tags About Device Beast sponsor

How to Define Fallback Routes in Laravel 8

Learn how to define fallback routes in Laravel and provide a user with a better page when no route matches the incoming request.

Created on Jun 30, 2021


In Laravel, you can make use of "Route::fallback" method to catch any incoming request that matches no route. Since typically any unhandled requests will automatically render the "404" page, having a fallback route inside the routes/web.php allow you to customize and return a custom route.

You can define the fallback route like below. The content of the view is up to your customization.

Route::fallback(function () {
  $message = 'You have hit a fallback page!';

  return view('page.fallback-page', ['message' => $message]);

Snippets by

PostSrc poster


Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

Load comments for How to Define Fallback Routes in Laravel 8


PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.

View Components

Other Code Snippets