docker - vue-router 历史模式在刷新时不起作用

标签 docker nginx vue.js vue-router

我将 vue-router 添加到我的项目中,它在基本设置下运行良好。但我想去掉 URL 中的井号 (#)。所以关注the documentation我切换到历史模式。我使用此链接 (<router-link to="/page/4">Open page</router-link>) 效果很好,但如果我尝试直接访问此页面(刷新),服务器将返回 404 错误屏幕。

我使用 nginx(docker 的 nginx:alpine 图像)这是默认文件:

server {
    root /var/www;
    index index.html index.htm;

    server_name localhost;

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

这是路由器:

new VueRouter({
  mode: 'history',
  routes: [
    {
      path: '/page/:id',
      component: page
    }
  ],
});

为什么返回404错误?

最佳答案

是nginx配置问题 将下面的配置插入到您的 nginx 服务器 block /配置中

error_page 404 /index.html;

关于docker - vue-router 历史模式在刷新时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48484940/

相关文章:

docker - “docker 历史”命令 : Why does the column label say 'IMAGE' when the column contains layers?

image - 我怎么能从无到有构建 docker 镜像?

vue.js - vuejs 历史模式与 github/gitlab 页面

mongodb - Kubernetes 杀死 Mongo 容器

phpMyAdmin导入文件大小限制2M

nginx - 如何在 CDN 后面创建反向代理(另一个反向代理)

rest - 如何为 RESTful API 配置 nginx?

vue.js - 如何正确地将数据从子组件传递到父组件以及将数据从父组件传递到子组件?

javascript - 如何正确使用 v-bind (vue.js)

docker - Linux Mint中的Docker错误