错误跳转html页面,[VUE CLI3] 多页面devServer 跳转 返回html错误问题

问题描述

最近尝试把项目脚手架从vue-cli2 webpack2 更新到vue/cli 3 webpack4

bVbgrRA?w=543&h=203

由于之前项目是多页面,在用脚手架生成了项目目录之后, 在vue-cli-service serve开发环境时发现了一些问题。

工程里有两个页面index和login, 也配了两个入口。但在默认页面中路由跳转都正常,但我点击按钮 通过window.location.href = '/login' 访问另一个页面login时,返回的资源依然是index.html和index.js

只有通过更改url访问 localhost:3007/login.html时,url会变成localhost: 3007/login/.html

这时候才会返回login.html和login.js

PS:通过 build打包之后访问后台(nodejs)访问一切都正常。

bVbgrX9?w=1484&h=915

bVbgrZA?w=1920&h=1080

bVbgr39?w=1476&h=539

项目目录

bVbgr2P?w=586&h=875

问题出现的环境背景及自己尝试过哪些方法

相关代码

vue.config.js

module.exports = {

devServer: {

port: 3007,

host: 'localhost',

open: true,

proxy: {

'/api': {

target: 'localhost: 3333',

changeOrigin: true,

// ws: true,

pathRewrite: {

'^/api': '/api'

}

}

}

},

chainWebpack: config => {

},

pages: {

index: {

// page 的入口

entry: 'src/main.js',

// 模板来源

template: 'public/index.html',

// 在 dist/index.html 的输出

filename: 'index.html',

// 当使用 title 选项时,

// template 中的 title 标签需要是

title: 'Index Page',

// 在这个页面中包含的块,默认情况下会包含

// 提取出来的通用 chunk 和 vendor chunk。

chunks: ['chunk-vendors', 'chunk-common', 'index']

},

login: {

entry: 'src/login.js',

template: 'public/login.html',

filename: 'login.html',

title: '登陆',

chunks: ['chunk-vendors', 'chunk-common', 'login']

},

// 当使用只有入口的字符串格式时,

// 模板会被推导为 `public/subpage.html`

// 并且如果找不到的话,就回退到 `public/index.html`。

// 输出文件名会被推导为 `subpage.html`。

// subpage: 'src/subpage/main.js'

},

}

你期待的结果是什么?实际看到的错误信息又是什么?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值