我正在努力在本地IIS上部署Vuejs前端。 我想将我的应用程序部署到名为FE_STB的文件夹中,该文件夹是C:\ inetpub \ wwwroot文件夹中的子目录。
理想情况下,用于访问前端的URL为http://localhost/FE_STB/。
为此,我在vue.config.js中尝试了以下操作:
module.exports = {
// Used to build the path for the css, js
baseUrl: process.env.NODE_ENV === 'production'
? '/FE_STB/'
: '/',
// The folder where the app will be built in the project directory instead of the default dist folder
// outputDir: 'Vue',
};
运行npm run build
会生成一个index.html,一个favicon.ico,我的img,js,css和fonts文件夹。
index.html包含诸如({<link href=/FE_STB/css/chunk-05c5.672f5bfa.css />
)之类的链接标记,我认为它朝着良好的方向发展。
但是,它不断返回
404找不到错误
当我尝试访问http://localhost/FE_STB/时。
另一方面,如果仅将index.html而不是FE_STB子目录复制到IIS安装的根目录(wwwroot)中,并检查http://localhost/ URL,则我的应用程序正确显示。
但是,当我开始浏览该应用程序并单击刷新按钮时,出现错误。例如,如果我在应用程序上的http://localhost/about/上并用F5刷新,则在查找C:\ inetpub \ wwwroot \ about \目录(显然不存在)时,会出现404错误。>
我还按照vuejs website所述尝试了web.config和IISrewrite解决方案,或者尝试添加:
const router = new VueRouter({
mode: 'history',
// To define sub-directory folder for the deployment
base: 'FE_STB',
routes,
linkActiveClass: 'active',
scrollBehavior(to, from, savedPosition) {
return savedPosition || { x: 0, y: 0 };
},
});
在我的router.js中,但没有任何改变。
任何提示或指示都会很有帮助。
谢谢
S。