Redirect after receiving Replay from server?

Asked

Viewed 594 times

1

I have an application that the front end is Vuejs/Quasar and the server is hapiJS. I am working on the login part and would like to know how to redirect the page after receiving confirmation from the server that the data entered in the login is correct.

Server:

server.route({
    path: '/login',
    method: 'post',
    handler: function (request, reply) {
        let user = request.query.login;
        let pass = request.query.senha;

        let pesquisa = {'usuario': {$eq: user}, 'senha': {$eq: pass}};

        db.open(function (err, mongoclient) {
            mongoclient.collection('login', function (err, collection) {
                collection.find(pesquisa).toArray(function (err, results) {
                    if (err) {
                        console.log(err);
                        mongoclient.close()
                    } else {
                        if (results === pesquisa) {
                            console.log('Login correto');
                            mongoclient.close();
                        }
                    }
                })
            })
        })
    }
}); 

Client:

entrar () {
    let self = this
    axios({
      url: '/server/login',
      method: 'post',
      params: self.pessoa
    })
      .then(function (response) {
        console.log(response.data)
        this.$route.router.go(response.data)
      })
      .catch(function (error) {
        console.log(error)
      })
  }

What should I send on server replay to the client??? How to redirect the page to the client after receiving the data from the server??

  • 1

    See if this helps you. link

  • Help yes, thank you very much

1 answer

1


You’ll need to set up a Router for your front-end app. The most commonly used Vue.js application is Vue-Router

After configuring the router, just use the command:

this.$router.push('/caminho/desejado')

For example, in its context, it should be done as follows:

.then(function (response) {
  // fazer alguma coisa com a resposta do servidor,
  // por exemplo, setar em algum componente que o usuário X está logado
  this.$router.push('/home')
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.