vue和我使用vue-cli 3来为auth0,qazxsw poi构建一个简单的身份验证应用程序。我的router.js模块是:
auth0-plugin.surge.sh
我期待当auth0回调到auth-plugin.surge.sh/callback时,我应该通过vue-router重定向到Callback组件。相反,我收到了/ callback页面的404错误。 webpack dev服务器按预期工作。使用serve npm包时发生同样的错误。阅读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;
使得部署到surge.sh似乎非常简单,不需要任何特殊措施。我用Google搜索并搜索了这个网站,但没有找到解决我问题的方法。任何帮助非常感谢。
好的,所以事实证明你需要一个200.html文件,如浪涌的网站Vue-cli deployment documentation所说,服务器作为使用vue-router时捕获所有路由。如果有人使用-s选项有Adding a 200.html page的经验,我会有兴趣知道你是如何使用的。希望在部署SPA时帮助其他人。在部署SPA时,对服务器配置进行了很好的记录,我找到了serve npm package