带Vue-cli3和静态站点的部署问题

艾伦

vue的新手,正在使用vue-cli3搭建auth0的简单身份验证应用auth0-plugin.surge.sh我的router.js模块是:

import Vue from "vue";
import Router from "vue-router";
import Home from "./views/Home.vue";
import Callback from "./views/Callback.vue";

Vue.use(Router);

const router = new Router({
  mode: "history",
  routes: [
    {
      path: "/",
      name: "home",
      component: Home
    },
    {
      path: "/callback",
      name: "callback",
      component: Callback
    }
  ]
});

// very basic "setup" of a global guard
router.beforeEach((to, from, next) => {
  // check if "to"-route is "callback" and allow access
  if (to.name == "callback") {
    next();
  } else if (router.app.$auth.isAuthenticated()) {
    // if authenticated allow access
    next();
  } else {
    // trigger auth0 login if not been authenticated before.
    // router.app refers to the root Vue instance the router was injected into
    router.app.$auth.login();
  }
});

export default router;

我期望当auth0回调到auth-plugin.surge.sh/callback时,我应该通过vue-router重定向到Callback组件。相反,我在/ callback页面上收到404错误。webpack开发服务器可以正常工作。使用serve npm软件包时,会发生相同的错误。阅读Vue-cli部署文档后,就可以很简单地知道将其部署到urge.sh不需要任何特殊措施。我已经搜索并搜索了该站点,但没有找到能解决我问题的方法。任何帮助,不胜感激。

艾伦

好的,所以事实证明,您需要一个如urge的网站上所述的200.html文件。为使用vue-router的服务器添加200.html页面作为捕获所有路由。如果有人对使用-s选项使用serve npm软件包有经验,我会很想知道您是如何使其工作的。希望这在部署SPA时对其他人有所帮助。我在这里找到了部署SPA时对服务器配置的良好记录

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章