问题
I'm using Laravel 5.4
and Vuejs 2.3
along with VueRouter
I have a website that consists of two parts
- example.com
- example.com/tools
Problem
If I am at example.com/tools
and if I reload the page
to the same address example.com/tools
the middleware checkUsersPublic
is triggered whereas it is only linked to /
.
Edit
If I remove { path: '/tools', component: Stats }
from VueRouter.js
the middleware is not triggered anymore
Question
- What should I do change so the middleware is not triggered ?
Routes in Laravel
Route::get('/', 'HomeController@home')->middleware('checkUserPublic')
Route::get('/tools', 'StatsController@home')->middleware('checkUserStats')
Vue router
const routes = [
{ path: '/', component: App },
{ path: '/tools', component: Stats },
];
Middleware checkUsersPublic
class checkUsersPublic
{
public function handle($request, Closure $next)
{
if(auth()->check() && auth()->user()->public_only) {
return $next($request);
}
if(Auth::check()) {Auth::logout();}
return $next($request);
}
}
回答1:
Instead of doing the middleware in Laravel
I did it within vue-router
in the beforeEnter
guard
来源:https://stackoverflow.com/questions/43939648/laravel-middleware-triggered-while-it-should-not