Home > Mobile >  Vuejs, can't go to my signup link directly, it goes back to login
Vuejs, can't go to my signup link directly, it goes back to login

Time:12-09

https://github.com/ahcene-bouazza/P7_Bouazza_Ahcene_Grouporama.git here is my github link for my project

  • My issue is that when I am in login page, I clique on signup "inscription" it opens me the Signup page fine, but when I refresh the browser it goes back to login page

  • Other issue is when I type my signup directly on my browser adresse "http://localhost:8080/signup" it does not go there but it goes to login page http://localhost:8080/

login page signup page

Thank you very much if you can find a solution for me it will be really much apreciated

CodePudding user response:

You in App.vue on mounted() call redirect this.$router.push('/'), but you have this.user.id only after login, without user data you call redirect to login page. It's incorrect. Just read documentaion Official docs and you will understand how to correct use protected routes.

Example router/index.js:

router.beforeEach((to, from, next) => {
  if (to.name !== 'Login' &&  to.name !== 'Signup' && !this.user.id == 0) next({ name: 'Login' })
  else next()
})

instead of App.vue

if (this.user.id == 0 && this.$router.currentRoute.path != '/') {
        this.$router.push('/')
      }
  • Related