Vue-router 在为生产构建后不会删除 hashbang [英] Vue-router doesn't remove hashbang after building for production
问题描述
我试图删除 hashbang,我通过在 vue-router 的索引文件中添加 mode:'history'
来实现的:
I was trying to remove the hashbang and I did it by adding mode:'history'
in the index file of vue-router:
export default new Router({
mode: 'history',
routes: [
{
path: '/',
name: 'Daksh',
component: Daksh
},
{
path: '/about',
name: 'About',
component: About
},
{
path: '/work',
name: 'Work',
component: Work
}
]
})
然后当我在热重载模式下尝试它时运行良好,但是在运行 npm run build
后,它由于某种奇怪的原因停止工作.
Then It was working well when I tried it in the hot reload mode but after running npm run build
, It stopped working for some weird reason.
请帮忙:)
推荐答案
由于答案已在评论中解决,并且 VonC 建议添加答案以便对其他人有所帮助,这是:
As the answer has been solved within the comments and as VonC suggested to add an answer so that it could be helpful for others , here it is:
由于您使用的是 nginx 来运行文件
Sinceyou are using nginx to run the files
Setup the server configuration for nginx as shown in example in the docs
location / {
try_files $uri $uri/ /index.html;
}
这篇关于Vue-router 在为生产构建后不会删除 hashbang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!