Skip to content

Instantly share code, notes, and snippets.

@srph
Created November 2, 2016 00:07
Show Gist options
  • Save srph/02fd1271ca3033a0fbd68c41e35c4daf to your computer and use it in GitHub Desktop.
Save srph/02fd1271ca3033a0fbd68c41e35c4daf to your computer and use it in GitHub Desktop.
Laravel - Catch all except /api routes. Useful for SPAs inside Laravel.
<?php
Route::get('{all}', function () {
return view('index');
})->where('all', '^((?!api).)*');
@mennovanhout
Copy link

You dont need to ignore api if you are using routes/api file because it is imported before the routes/web file by

https://github.com/laravel/laravel/blob/fc79b8bb1130309278b462ea01cb6c067e3befb1/app/Providers/RouteServiceProvider.php#L41

Hi, I don't agree. You should still ignore API for debug purposes.
If you use a not allowed methode or route that's created wrong (Forgotten or typo). You'd like to get the Laravel arror instead of the SPA.
I still recommend ignoring /api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment