我正在将VueJS与Vue路由器一起使用。由于将Firebase auth域从默认的example.firebaseapp.com更改为example.com,使用户使用其Google帐户进行身份验证的重定向不再起作用。重定向停留在https://example.com/__/auth/handler?apiKey=X&appName=X&authType=signInViaRedirect&providerId=google.com
firebase.initializeApp({
apiKey: "123456789",
authDomain: "example.com",
databaseURL: "https://example.firebaseio.com",
projectId: "example",
storageBucket: "example.appspot.com",
messagingSenderId: "123456789"
});
我尝试删除htaccess并添加重定向URL /__/auth/
作为路由路径。
router.js:
import Vue from "vue";
import router from "vue-router";
import Signup from "./components/User/Signup";
import AuthGuard from "./auth-guard";
import NotFound from "./components/User/NotFound";
Vue.use(router);
export default new router({
routes: [
{
path: "/",
name: "Home",
component: Home
},
{
path: "/signup",
name: "Signup",
component: Signup
},
{ path: "*", name: "NotFound", component: NotFound }
],
mode: "history"
});
auth-guard.js
import store from "./store";
export default (to, from, next) => {
if (store.getters.user) {
next();
} else {
next("/signup");
}
};
如何使重定向工作?
您是否仍将网站托管在Firebase上,因此example.com重定向到example.firebaseapp.com?如果是这种情况,我可以假设服务器端重定向未将url路径传递给最终服务器。在这种情况下,您需要设置服务器端路由。 Vue Router仅处理客户端url解析。
也许此答案将帮助您前进:https://stackoverflow.com/a/36623117/5707212