0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for your response @Delena Malan. What I want in my application is, if user clicks on a link it should not reload the page but render the page in a ng-view. Can I do this and how?
Yes, have a look at ngRoute. It should do what you're looking for :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.