0

Creating an app with the two languages, ng for FrontEnd then Laravel serving its requests from the backend. Now, given that these two languages have routing, how do i avoid the routes from conflicting? In my routes.php i have:

 Route::get('/', function()
{
    return View::make('index');
});

Route::group(array('prefix'=>'api'), function()
{
    return Route::resource('students','StudentController');
});

App::missing( function($exception) {
    return Redirect::to( '/' );
});

and in my app.js something like this:

var studentApp = angular.module('studentApp', ['controllers', 'studentService','ngRoute']);
studentApp.config(['$routeProvider',function($routeProvider) {
$routeProvider
.when('/', {
    controller: 'MainController',
    templateUrl: '/partials/list.html'
    })
.when('/add', {
    controller: 'StudentController',
    templateUrl: '/partials/add.html'
    })
.otherwise({redirectTo: '/'});
}]);

When i try to use the above, nothing is working. I'm wondering whether the two types of routing are conflicting. Or what is the best way of blending the two routings?

1 Answer 1

1

Its generally well known that you can build an app with Laravel on the back end and AngularJS on the backend - and not have the routes conflict.
Angular uses a hashtag between the main URL and its own URL route segments, which the browser doesn't detect as a route change (and therefore wont trigger a server side request), but angular will respond to.
I'm not sure about the routing compatibility with HTML5 mode, but you dont have it enabled, so I wouldn't worry about that.

Resources

here are 3 resources that were helpful for me to work out how to set up AngularJS and Laravel together.

Your current issue

I would suggest the the reason your app is not working is for some other unrelated reason

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

1 Comment

Just in case it might help somebody, the main reason why my routing was not working very well is (as someone mentioned somewhere) that angular.js and angular-route.js were not of the same version. i changed them to a same version and everything worked well.

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.