Redirect after receiving response from the server?

1

I have an application that the front end is VueJS / Quasar and the server is hapiJS. I'm working on the login part and would like to know how to redirect the page after receiving confirmation from the server that the login information 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 do in the response from the server to the client ??? How to redirect the page on the client after receiving the data from the server ??

    
asked by anonymous 25.08.2017 / 16:56

1 answer

1

You'll need to set up a Router for your front-end app. The most used in Vue.js applications is the Vue-Router

After setting up 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')
})
    
03.09.2017 / 21:59