我目前正在使用VueJS SPA,VueJS路由器和Laravel构建新的Web应用程序,用户应该能够以访客身份(未经身份验证)或登录的身份访问页面。在(已认证)!
我为SpaController包含$this->middleware('auth')
,将访问我的页面仅限制为经过身份验证的用户,但是某些页面(路由)也应该可以公开访问,但应属于SPA。
我如何使/:username
,/:username/places
路由可公开访问?
这是我的routes.js
文件的外观:
import VueRouter from 'vue-router';
import Cities from './views/Cities';
import Places from './views/Places';
import Home from './views/Home';
import Dashboard from './views/Dashboard';
import NotFound from './views/NotFound';
let routes = [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/404',
name: '404',
component: NotFound
},
{
path: '/:username',
name: 'dashboard',
component: Dashboard,
children: [
{
path: 'places',
name: 'places',
component: Places
},
]
},
{
path: 'cities',
name: 'cities',
component: Cities
},
{
path: '*',
redirect: '/404'
},
];
export default new VueRouter ({
mode: 'history',
routes
});
可以通过laravel
route
]完成>
在routes>api.php
文件中,
Route::middleware('auth:api')->group(function(){ // contains the api controllers to be accessed when user is logged in } //list of routes to be accessed publicly goes here, e.g. Route::get('/userworkexperience/{user}', 'ControllerName@method')->name('something.else');
我希望这会有所帮助