如何同时使用Laravel身份验证和vue路由器
我一般不熟悉Laravel和PHP,但熟悉Vue和SPA。例如,我知道如何使用Bcrypt创建身份验证。但是,我使用Laravel运行如何同时使用Laravel身份验证和vue路由器,laravel,laravel-5,vue.js,routes,vue-router,Laravel,Laravel 5,Vue.js,Routes,Vue Router,我一般不熟悉Laravel和PHP,但熟悉Vue和SPA。例如,我知道如何使用Bcrypt创建身份验证。但是,我使用Laravel运行php artisan make:auth,并为后端创建几个不同的端点 我试图使用Vue将我的应用程序转换为SPA,但是使用Vue路由会导致web.php中定义的路由出现问题。例如,我的web.php是这样的,有几个不同的路径 <?php Route::get('/{vue_capture?}', function () { return view
php artisan make:auth
,并为后端创建几个不同的端点
我试图使用Vue将我的应用程序转换为SPA,但是使用Vue路由会导致web.php中定义的路由出现问题。例如,我的web.php是这样的,有几个不同的路径
<?php
Route::get('/{vue_capture?}', function () {
return view('app');
})->where('vue_capture', '^(?!storage).*$');
Route::get('/', function () {
return view('app');
});
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');
我知道如果您使用SPA,Vue应该接管路由,但有没有办法同时使用这两种方式?我找不到任何解决这个问题的方法,但我不相信Laravel会让你选择使用他们的内置命令,比如php artisan make:auth
,或者如果你想要一个带有路由的SPA,就必须放弃所有这些,全部手动完成
我尝试过使用Laravel和/或Vue处理不同的积垢。
我已尝试将所有路由定向到Vue,以使Vue路由器处理路由。
我尝试过不将所有路由提供给vue路由器,并保留web.php中的后端路由
另一个半相关的问题是,我的路由甚至没有显示为使用
路由器链接的链接。它只是显示为普通文本。但目前我的首要任务是路由问题。您可以将vue路由和Laravel路由结合起来。但为了获得最佳效果,我建议您使用vue路由器,因为您正在构建spa
除去
将所有后端路由放在指向vue的路由之前
另外,验证您的后端没有冲突的路由(运行php artisan route:list
查看您的laravel路由列表)和vue路由。我希望这能有所帮助。公认的答案是完美的(我投了更高的票,但我还没有代表可以计算),而且对我来说效果很好,但前提是我还创建了“虚拟”vue组件并将其导入到路由中。希望这有帮助
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 },
你可以用这个来代替
Route::get('/{vue_capture?}', function () {
return view('app');
})->where('vue_capture', '^(?!storage).*$')->middleware('auth');
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).*$');
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 },
Route::get('/{vue_capture?}', function () {
return view('app');
})->where('vue_capture', '^(?!storage).*$')->middleware('auth');