I can redirect using
res.writeHead(302, {
Location: 'http://localhost:8080/path'
})
But I need to send some data along with redirection. How can I do that?
One way to pass data from redirecting is to put it as a query param, for example
res.writeHead(302, {
Location: 'http://localhost:8080/path?data=1'
})
and on your vue app, you can get the query param with:
this.$route.query.data
Keep in mind that this is not secure and not recommended if you are passing a sensitive data.
EDIT:
You can also pass the data as path params if it fits your need, for example you have your vue route like this:
routes: [
{
path: '/path/:data',
name: 'path',
component: PathPage,
},
]
you can redirect from your express app like this:
res.writeHead(302, {
Location: 'http://localhost:8080/path/50'
})
and you can get the parameter from your vue component like this:
this.$route.params.data // 50
I think listen()
method is what you need for nodejs backend server.
var http = require('http');
var url = require('url');
http.createServer(function (req, res) {
console.log("Request: " + req.method + " to " + req.url);
res.writeHead(200, "OK");
res.write("<h1>Hello</h1>Node.js is listening new port");
res.end();
}).listen(3000);
Thread: Changing Node.js listening port