gpt4 book ai didi

javascript - Vue.js 路由从子目录服务

转载 作者:可可西里 更新时间:2023-11-01 02:35:33 26 4
gpt4 key购买 nike

我想从暂存服务器上的子目录提供我的 Vue.js 应用程序。例如:http://url.com/subdir/app/

现在,如果我这样做并设置构建配置 assetsPublicPath 以从该文件夹提供服务,所有 Assets 都可以正常提供,但我的应用程序无法正确路由。 “主页”页面被路由到“包罗万象”,任何进一步的路由只会显示正常的白页 404。

这是我的路由器:

export default new Router({
mode: 'history',
routes: [
{
path: '/',
component: ContentView,
children: [
{
path: '/',
name: 'DataTable',
component: DataTable,
meta: { requiresAuth: true }
},

// ===================================
// Login
// ===================================
{
path: '/login',
name: 'AppLogin',
component: AppLogin,
meta: { checkAlreadyLoggedIn: true }
},
{
path: '/logout',
name: 'AppLogout',
component: AppLogout,
meta: { requiresAuth: true }
}
]
},
{
path: '*',
component: ContentView,
children: [
{
path: '/',
name: 'NotFound',
component: NotFound
}
]
}
]})

这是必要的 config/index.js 更改:assetsPublicPath: '/subdir/app/'

在本地开发中,路由运行良好。但是在登台服务器上,所有静态 Assets 、内置的 JS 和 CSS 等都可以正常使用。然而,家庭路线显示了一切。我假设这是因为我的路由设置不正确,或者因为我需要做一些事情来从生产中的子目录提供服务。

最佳答案

assetsPublicPath 配置仅用于 webpack Assets 。对于vue-router,需要在构造函数中设置base选项。

参见文档:https://router.vuejs.org/en/api/options.html#base

关于javascript - Vue.js 路由从子目录服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43918367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com