https://github.com/ahcene-bouazza/P7_Bouazza_Ahcene_Grouporama.git 這是我專案的 github 鏈接
我的問題是,當我在登錄頁面時,我在注冊“銘文”上建立了一個小組,它可以很好地打開我的注冊頁面,但是當我重繪 瀏覽器時,它會回傳到登錄頁面
另一個問題是當我直接在我的瀏覽器地址“http://localhost:8080/signup”上輸入我的注冊時,它不會去那里,但它會轉到登錄頁面 http://localhost:8080/
登錄頁面 注冊頁面
非常感謝您,如果您能為我找到解決方案,那將非常感謝
uj5u.com熱心網友回復:
您在App.vue上mounted()呼叫重定向this.$router.push('/'),但你this.user.id僅在登錄后,沒有用戶資料的呼叫重定向到登錄頁面。這是不正確的。只需閱讀檔案官方檔案,您就會了解如何正確使用受保護的路由。
示例router/index.js:
router.beforeEach((to, from, next) => {
if (to.name !== 'Login' && to.name !== 'Signup' && !this.user.id == 0) next({ name: 'Login' })
else next()
})
代替 App.vue
if (this.user.id == 0 && this.$router.currentRoute.path != '/') {
this.$router.push('/')
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/377030.html
標籤:Vue.js 验证 Vue路由器 页面刷新 路由器链接
上一篇:vue從組件更改div
