vue cli3 打包後訪問不到頁面 Failed to load resource: the server responded with a status of 404 (Not Found)

在根目錄下新建文件vue.config.js

配置打包資源路徑:默認是“./”,如果沒有特殊需求就不要修改

 代碼如下:

const path = require('path')
function resolve(dir) {
    return path.join(__dirname, dir)
}
module.exports = {
    publicPath: './static', //這個路徑根據自己的情況定,默認就填"./",因爲我靜態資源的路徑必須要在static文件夾下,所以才修改的。
    devServer: {  //配置服務器的,添加之後使用npm run dev會自動打開頁面
        open: true
    },
    configureWebpack: {
        resolve: {
            alias: {
                '@': resolve('src')
            }
        }
    }
}
這是我的部署目錄結構,這個 publicPath路徑,其實就是相對index.html的路徑,可以根據自己的需求修改

路由模式使用Hash模式

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章