anonymus
anonymus

Reputation: 171

How to handle Laravel routing using AngularJs?

I am completely new to Laravel + AngularJs. What I want to do is handle my web.php routes using AngularJs. Is it possible? If it how can I do that?

Upvotes: 0

Views: 202

Answers (1)

D Malan
D Malan

Reputation: 11464

If you have an SPA and your app is using HTML5 history mode, this should be similar to how people often combine Laravel and VueJS routing.

You'd usually have all of your non-Angular routes at the top of routes/web.php and then a "catch-all" route for your SPA. This "catch-all" route is basically a route that doesn't care what the route looks like; it will just send it on to the AngularJS app.

Similar to this answer or this article your routes/web.php might look something like:

Route::resource('Videos', 'VideoController')->middleware('auth','isAdmin');
Route::resource('Categories', 'CategoriesController')->middleware('auth');
...
Route::get('/{angularjs_capture?}', function () {
 return view('angularjs.index');
})->where('angularjs_capture', '[\/\w\.-]*');

And then you'd have a view at /resources/views/angularjs/index.blade.php that contains the base HTML for your SPA.

Upvotes: 1

Related Questions