Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do bonus routes in Statamic differ from standard Laravel routes in terms of priority
    Laravel Service Provider


How do bonus routes in Statamic differ from standard Laravel routes in terms of priority


the key differences between Statamic's "bonus routes" and standard Laravel routes in terms of priority are:

1. Route Prioritization: The search results indicate that custom Laravel routes take priority over Statamic's routes. This means that if you define a bonus route that conflicts with a Statamic route, the Laravel route will take precedence and override the Statamic route.

As stated in the Bonus Routes addon documentation: "If you define a bonus route that's the same as a Statamic route it will override Statamic. This should be avoided, it's best to use Statamic's routing wherever possible."[1]

2. Statamic's Routing Handling: Statamic provides its own `Route::statamic()` method to handle content-driven routing, such as for collection entries and taxonomy terms. These Statamic-specific routes are handled separately from your standard Laravel routes.[5]

3. Exclusion from Laravel's Route Handling: To ensure that Statamic's routes, including the control panel routes, are properly prioritized, you need to exclude them from Laravel's route handling. This is done by adding specific middleware and prefix handling in the `RouteServiceProvider`.[2]

4. Bonus Routes Addon: The "Bonus Routes" addon for Statamic simplifies the process of defining additional collection and taxonomy-based routes. However, it still emphasizes that custom Laravel routes take priority over these bonus routes.[1]

In summary, while Statamic provides its own routing mechanisms, custom Laravel routes will always take precedence over Statamic's routes. To ensure proper integration and prioritization, you need to carefully manage the exclusion of Statamic's routes from Laravel's route handling and be mindful of any potential conflicts between your custom Laravel routes and Statamic's routes.

Citations:
[1] https://statamic.com/addons/jacksleight/bonus-routes
[2] https://statamic.dev/controllers
[3] https://laracasts.com/discuss/channels/laravel/routes-priority
[4] https://laracasts.com/discuss/channels/laravel/is-it-possible-to-prioritize-a-packages-routes
[5] https://statamic.dev/routing