How to use Laravel authentication and vue-router together
You can combine both vue route and Laravel route. But for the best result, I advise you use vue router since you are building an spa.
- remove
Route::get('/', function () { return view('app');});
- put all the backend route before the route that point to your vue.
Route::resource('Videos', 'VideoController')->middleware('auth','isAdmin');Route::resource('Categories', 'CategoriesController')->middleware('auth');Route::get('/search', 'VideoController@search')->middleware('auth');Auth::routes();Route::get('/settings/account', 'AccountsController@edit')->middleware('auth');Route::get('/auth', 'AccountsController@get');Route::put('/settings/account', 'AccountsController@update')->middleware('auth');Route::get('/{vue_capture?}', function () { return view('app'); })->where('vue_capture', '^(?!storage).*$');
Also, verify that you don't have conflicting routes on your backend (run php artisan route:list
to see your laravel route list) and vue routes. I hope this helps.
The accepted answer is perfect (I upvoted but I have no rep yet for it to count) and worked well for me but only under the condition if I also created 'dummy' vue components and imported them to work with the routes. Hope this helps!
import Login from './auth/Login'import Register from './auth/Register'import Logout from './auth/Logout'{ path:'/login', component:Login },{ path:'/register', component:Register },{ path:'/logout', component:Logout },
You can just use this instead
Route::get('/{vue_capture?}', function () { return view('app'); })->where('vue_capture', '^(?!storage).*$')->middleware('auth');