vue在history模式下如何配置相關(guān)文件和后端ngnix配置

vue history模式 部署在服務(wù)器端的nginx配置 (非根目錄)

vue history需要nginx或者其他方式配置一下才可正確訪問,否則路由跳轉(zhuǎn)之后刷新一下便會出現(xiàn)404

最近遇到的問題是上了一個小的項目,需要放在更深層次的目錄下,上到測試環(huán)境 做了官網(wǎng)提到的nginx配置發(fā)現(xiàn)不行,之后查閱了一些博客資料,發(fā)現(xiàn)都沒有一個特別好的方案。最終,我的解決方案如下

nginx配置如下

server {

? ? ? ? listen? ? ? 443 ;

? ? ? ? server_name? m;

? ? ? ?

? ? ? ? root? html/mobile;

? ? ? ? location / {

? ? ? ? ? ? index? index.html index.htm;

? ? ? ? ? ? try_files $uri $uri/ /auth/index.html;

? ? ? ? }

? ? }

vue router 配置

// 路由配置

const RouterConfig = {

? base: "/auth/",

? mode: 'history',

? routes: routers

};

該項目是用的vue-cli2 所以只需要修改config 里面的index.js的build部分

webpack 配置修改

build: {

? ? // Template for index.html

? ? index: path.resolve(__dirname, '../dist/auth/index.html'),

? ? // Paths

? ? assetsRoot: path.resolve(__dirname, '../dist'),

? ? assetsSubDirectory: 'auth/static',

? ? assetsPublicPath: '/',

? ? /**

? ? * Source Maps

? ? */

? ? productionSourceMap: false,

? ? devtool: '#source-map',

? ? productionGzip: false,

? ? productionGzipExtensions: ['js', 'css'],

? ? bundleAnalyzerReport: process.env.npm_config_report

? }

最終項目地址為 m.xxx.com/auth/

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容