如何允许用户使用VueJS Router / SPA公开访问某些路由

问题描述 投票:0回答:1

我目前正在使用VueJS SPAVueJS路由器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 vue.js single-page-application vue-router laravel-api
1个回答
0
投票

可以通过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');

我希望这会有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.