php - Combine AngularJS and Laravel Routing -


i using angularjs , laravel web app project. routing this:

angularjs:

angular.config(['$stateprovider','$urlrouterprovider',function($stateprovider,$urlrouterprovider) {     $urlrouterprovider.otherwise('/');      $stateprovider     .state('home', {             url: '/',             templateurl: '/admin/dashboard'         }); }]); 

laravel:

route::group(array('prefix'=>'admin', function(){     route::get('/', ['as'=>'admin.main',function(){         return view('main');     }]);      route::get('/dashboard', ['as'=>'admin.dashboard',function(){         return view('dashboard');     }]); }); 

i facing problem need declare route path @ 2 place. 1 @ angular , other 1 @ laravel. so, every time when add new route or change route path, need work on 2 place. become tedious , hard maintain when app grows.

is there anyway need set route url @ 1 place, effective both?

i assume you're building single-page app. means on server-side (laravel) need use same template requests, e.g.

route::group(['prefix' => 'admin'], function() {     route::get('(.*)', function() {         return view('dashboard');     }); }); 

on client-side (angularjs) you're doing routing described in question.


btw, you're using wrong syntax in laravel routing, incorrect:

route::get('/', ['as'=>'admin.main',function(){ }]); 

and how should be:

route::get('/', ['as'=>'admin.main'],function(){ //                                 ^ }); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -