Javascript 后模式:';历史';vue路由器不';行不通
我最近开始学习vuejs,并使用firebase构建和应用程序进行身份验证。 我在安装webpack主题并尝试删除链接上的默认标签后遇到问题。当我插入Javascript 后模式:';历史';vue路由器不';行不通,javascript,firebase,vue.js,firebase-authentication,vuejs2,Javascript,Firebase,Vue.js,Firebase Authentication,Vuejs2,我最近开始学习vuejs,并使用firebase构建和应用程序进行身份验证。 我在安装webpack主题并尝试删除链接上的默认标签后遇到问题。当我插入mode:history时,它不会在我登录hello页面后重定向我。当我移除它时,一切正常 My index.js(在我的路由器文件夹下): 下面是我的登录按钮示例: <button class="btn" type="submit" v-on:click="signIn">Log In</button> 登录 和我的组
mode:history
时,它不会在我登录hello页面后重定向我。当我移除它时,一切正常
My index.js(在我的路由器
文件夹下):
下面是我的登录按钮示例:
<button class="btn" type="submit" v-on:click="signIn">Log In</button>
登录
和我的组件脚本:
<script>
import firebase from 'firebase'
export default {
name: 'login',
data: function() {
return {
email: '',
password: ''
}
},
methods: {
signIn: function() {
firebase.auth().signInWithEmailAndPassword(this.email, this.password).then(
(user) => {
this.$router.replace('hello')
},
(err) => {
alert('Oops. ' + err.message)
}
);
}
}
}
</script>
从“firebase”导入firebase
导出默认值{
名称:'登录',
数据:函数(){
返回{
电子邮件:“”,
密码:“”
}
},
方法:{
签名:函数(){
firebase.auth()(
(用户)=>{
此。$router.replace('hello'))
},
(错误)=>{
警报('Oops.'+错误消息)
}
);
}
}
}
这是否与v-on:click
功能有关
如果您还需要什么来解决我的问题,请告诉我。案件很重要
替换
this.$router.replace('hello')
与
也代替
next('login')
与
或
我应该把
next('/login')
放在哪里?这里if(requireauth&&!currentUser)next('login')
和下一行我更新了答案。您需要通过名称或路径显式调用路由。案例很重要。你是否更改了所有实例?与next('hello')一样,您应该在登录实例中使用.push而不是.replace。如果用户单击后退按钮,他们希望返回登录页面,而不是之前的任何页面。一般来说,“替换”在大多数情况下都不是一个很好的用户体验。不,它很好,就像我之前在删除历史记录模式时提到的,一切都很好。请显示您的整个模板代码
this.$router.replace('Hello')
next('login')
next('/login')
next('Login')