Laravel子路径中的Vue路由器找不到正确的组件

时间:2019-12-02 20:49:09

标签: laravel vue.js vue-router

我在另一个Laravel / Vue项目上运行了几乎相同的配置,该项目运行得很好,但是在主路径/上。在这里,我将Vue实例分组到admin子路由中,将我在管理员路由到我已设置的PageNotFound组件后键入的所有内容进行分组。

我在web.php中的路线:

Route::group(['prefix' => 'admin'], function() {
    Route::get('/{route?}', 'AdminController@index')
    ->where('route', '.*')->fallback();
});

我的Vue路由器设置:

const router = new VueRouter({
    mode: 'history',
    // linkActiveClass: 'active',
    linkExactActiveClass: 'exact-active',
    routes: [
        {
            path: '/', // Solution: '/admin' not just '/'
            component: Dashboard,
            meta: {
                title: 'Dashboard',
                metaTags: [
                    {
                        name: 'description',
                        content: 'The about page of our example app.'
                    },
                    {
                        property: 'og:description',
                        content: 'The about page of our example app.'
                    }
                ]
            },
        },
        {
            path: '*',
            component: PageNotFound,
            meta: {
                title: '404 - Page Not Found',
                metaTags: [
                    {
                        name: 'description',
                        content: 'The about page of our example app.'
                    },
                    {
                        property: 'og:description',
                        content: 'The about page of our example app.'
                    }
                ]
            },
        }
    ],
});

解决方案:

似乎Vue Router不在乎我在Laravel中定义的任何前缀,而是查找完整路径,因此在上面的仪表板中,我将路径指定为/,它实际上应该是/admin

1 个答案:

答案 0 :(得分:0)

admin在Web服务器中保留,例如,使用管理员作为前缀