解決vue 打包發(fā)布去#和頁面空白的問題
1.vue項(xiàng)目中config文件下index.js中打包配置
build: { // Template for index.html index: path.resolve(__dirname, '../yiTownWebApp/index.html'), // Paths assetsRoot: path.resolve(__dirname, '../yiTownWebApp'), assetsSubDirectory: 'static', assetsPublicPath: '/yiTownWebApp/',//這個(gè)地方使用絕對路徑很重要 /** * Source Maps */ productionSourceMap: true, // https://webpack.js.org/configuration/devtool/#production devtool: '#source-map', // Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. // Before setting to `true`, make sure to: // npm install --save-dev compression-webpack-plugin productionGzip: false, productionGzipExtensions: ['js', 'css'], // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report }
2.路由配置:router文件夾下index.js
export default new Router({ mode: 'history',//去掉#, base: '/yiTownWebApp/',//這個(gè)配置也很重要,否則會(huì)出現(xiàn)頁面空白情況 scrollBehavior: () => ({ y: 0 }), routes: [ { path: '/article', name: 'article', component: article }, { path: '/footMark', name: 'FootMark', component: FootMark }, { path: '/shareFootMark', name: 'ShareFootMark', component: ShareFootMark } ] })
nginx配置:
server { listen 8080; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #打包后的項(xiàng)目目錄,一定記住這個(gè)地方帶有項(xiàng)目名稱 root /Users/a123/Desktop/vue/sgAdmin/yiTownWebApp; index index.html; location /yiTownWebApp{ #這個(gè)地方?jīng)]有項(xiàng)目名稱,因?yàn)檎埱蟮臅r(shí)候如果請求:http://localhost:8080/yiTownWebApp,nginx會(huì)查找/Users/a123/Desktop/vue/sgAdmin/yiTownWebApp/目錄下的數(shù)據(jù) root /Users/a123/Desktop/vue/sgAdmin; try_files $uri $uri/ @router; index index.html; } //try_files $uri $uri/ @router;和下邊部分很重要,沒有這部分發(fā)布二級一下的路由會(huì)出現(xiàn)js加載,但是也沒空白的情況 location @router { rewrite ^.*$ /index.html last; } }
以上這篇解決vue 打包發(fā)布去#和頁面空白的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
淺談Vue中的this.$store.state.xx.xx
這篇文章主要介紹了Vue中的this.$store.state.xx.xx用法,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09Vue自定義指令結(jié)合阿里云OSS優(yōu)化圖片的實(shí)現(xiàn)方法
這篇文章主要介紹了Vue自定義指令結(jié)合阿里云OSS優(yōu)化圖片的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11vue中設(shè)置height:100%無效的問題及解決方法
這篇文章主要介紹了vue中設(shè)置height 100%無效的問題及解決方法,需要的朋友可以參考下2018-07-07Vue引入highCharts實(shí)現(xiàn)數(shù)據(jù)可視化
這篇文章主要為大家詳細(xì)介紹了Vue引入highCharts實(shí)現(xiàn)數(shù)據(jù)可視化,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03element中Select選擇器實(shí)現(xiàn)自定義顯示內(nèi)容
在我們很多前端業(yè)務(wù)開發(fā)中,往往為了方便,都需要自定義一些用戶組件,本文主要介紹了element中Select選擇器實(shí)現(xiàn)自定義顯示內(nèi)容,感興趣的可以了解一下2023-12-12vue+node 實(shí)現(xiàn)視頻在線播放的實(shí)例代碼
這篇文章主要介紹了vue+node 實(shí)現(xiàn)視頻在線播放的實(shí)例代碼,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10使用Mockjs模擬接口實(shí)現(xiàn)增刪改查、分頁及多條件查詢
Mock.js是一個(gè)模擬數(shù)據(jù)生成器,可以讓前端獨(dú)立于后端進(jìn)行開發(fā),下面這篇文章主要給大家介紹了關(guān)于使用Mockjs模擬接口實(shí)現(xiàn)增刪改查、分頁及多條件查詢的相關(guān)資料,需要的朋友可以參考下2022-04-04vue3配置Element及element-plus/lib/theme-chalk/index.css報(bào)錯(cuò)的解決
這篇文章主要介紹了vue3配置Element及element-plus/lib/theme-chalk/index.css報(bào)錯(cuò)的解決,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03