我已经构建了vue MPA应用程序,并且一切都在开发模式下运行良好,但是在生产模式下,所有组件都以index.html模板呈现,甚至应以admin.html模板呈现的组件也是如此。我正在使用.htaccess来处理vue-router历史记录模式。有谁想帮忙吗?
我试图用.htaccess解决问题,但是它不起作用。
RewriteEngine On
RewriteBase /admin/
RewriteRule ^admin\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /admin.html [L]
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
//在vue.config.js中
module.exports = {
pages: {
index: {
entry: 'src/index/main.js',
template: 'public/index.html',
filename: 'index.html',
title: 'Index Page',
chunks: ['chunk-vendors', 'chunk-common', 'index']
},
admin: {
entry: 'src/admin/main.js',
template: 'public/admin.html',
filename: 'admin.html',
title: 'Admin Page',
chunks: ['chunk-vendors', 'chunk-common', 'admin']
}
},
devServer: {
historyApiFallback: {
rewrites: [
{ from: /\/index/, to: '/index.html' },
{ from: /\/admin/, to: '/admin.html' }
]
}
}
}