dawiyo's avatar

Route precedence issue when combining Laravel and Angular routing

So I have a site mixing Laravel and Angular working in production. Page routing is working through the following code:

Route::any( '{path?}', [ 'uses' => 'PagesController@index' ])->where('path', '.+');

However, when I add another route above that catch-all route, it seems Laravel is ignoring it. Even when I go directory to the URL (as opposed to clicking a link with this route), it still prefers the catch-all.

// For example:
Route::get('downloads/*', function() {
  return 'test';
});

Route::any( '{path?}', [ 'uses' => 'PagesController@index' ])->where('path', '.+');

I'm trying to solve the issue of when a user clicks on a link to an uploaded file in the '/uploads' directory, it just gets passed to Angular and fails. Any ideas on why Laravel routing would ignore the precedence like this?

0 likes
1 reply
jhoff's avatar

In your example, 'downloads/*' is incorrect... that will only match the literal url 'http://example.com/downloads/*'

Do you perhaps want to do something like this?

Route::get('downloads/{id}', function( $id ) {
  return 'download - ' . $id;
});

Please or to participate in this conversation.