Vue-router 在为生产构建后不会删除 hashbang

Vue-router 在为生产构建后不会删除 hashbang

问题描述:

我试图删除 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​​trong> 建议添加答案以便对其他人有所帮助,这是:

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

文档中的示例所示,为 nginx 设置服务器配置一个>

Setup the server configuration for nginx as shown in example in the docs

location / { 
    try_files $uri $uri/ /index.html; 
}